Tell us what’s happening:
When I return noRepeat.length it is always 0 even though when I return noRepeat itself, the array returns just fine.
Your code so far
function permAlone(str) {
var result = [];
if (str.length == 1) {
result.push(str);
return result;
}
for (var i = 0; i < str.length; i++) {
var baseChar = str[i];
var otherChars = str.substring(0, i) + str.substring(i + 1);
var innerPerm = permAlone(otherChars);
for (var j = 0; j < innerPerm.length; j++) {
result.push(baseChar + innerPerm[j]);
}
}
var regex = /(.)\1+/g;
var noRepeat = result.filter(function(string) {
return !string.match(regex);
});
return noRepeat.length;
}
permAlone('aab');
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (X11; CrOS x86_64 10032.86.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.140 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/no-repeats-please