Tell us what’s happening:
I can not quite figure out why the function repeats the string permutation two times at the begining in a linear way.. It has me stuck at number 4
Your code so far
const permuteString = (str, prefix="", resultsArr=[]) => {
if(str.length === 0){
resultsArr.push(prefix);
return resultsArr
}else{
for(let i = 0; i < str.length; i++){
const newStr = str.slice(0, i) + str.slice(i+1);
const newPre = prefix + str[i]
permuteString(newStr, newPre, resultsArr)
}
}
return resultsArr
}
console.log(permuteString("fcc"))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a Permutation Generator - Build a Permutation Generator