my test is logging the correct result, but I feel like for some reason when I call the method it does’nt return the correct array, what am I missing here?
Your code so far
function permuteString(string, prefix = '', array = []){
if(string.length === 0) {
array.push(prefix);
if(array.length == getPermuteAmount(prefix.length))
{
console.log([...new Set(array)]);
return [...new Set(array)];
}
}
for(const char in string){
let s = string.split("");
s.splice(char, 1);
s = s.join("");
permuteString(s, prefix + string[char], array);
}
}
function getPermuteAmount(length){
let amm = 0;
let len = length;
while(len > 0){
amm += len;
len--;
}
return amm;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0
Challenge Information:
Build a Permutation Generator - Build a Permutation Generator