I’ve been trying to do this challenge for a while now and I’ve come up with this code so far.
I don’t understand what I’m doing wrong. When I do console.log(arr) it just shows an empty array.
Can someone help me figure out what’s wrong?
Your code so far
function permAlone(str) {
var regex = /(.)\1+/;
var arr = permutator(str, "");
arr = arr.filter(word => !regex.test(word));
return arr.length;
}
function permutator(string, permutation) {
var results = [];
if (!string.length) {
results.push(permutation);
}
for (var i = 0; i < string.length; i++) {
permutation += string[i];
var otherChars = string.slice(0, i) + string.slice(i + 1)
permutator(otherChars, permutation);
permutation = permutation.slice(0, permutation.length - 1);
}
return results;
}
permAlone('aab');
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0
.
Challenge: No Repeats Please
Link to the challenge:
https://www.freecodecamp.org/learn/coding-interview-prep/algorithms/no-repeats-please