Answers for "recursive permutation"

0

recursive permutation

function findPerms(str) {  
      if (str.length === 1) return [str]    
      let all = []  
      
      for (let i = 0; i < str.length; i++) {    
        const currentLetter = str[i]    
        const remainingLetters = str.slice(0,i) + str.slice(i+1) 
        const permsOfRemainingLetters = findPerms(remainingLetters)
        
        permsOfRemainingLetters.forEach(
          subPerm => {all.push(currentLetter + subPerm)}
        )    
      }  
      return all
    }
Posted by: Guest on June-04-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language