# Getting stuck on the "No Repeats Challenge"

I’m getting stuck in one of the front-end web dev challenges regarding permutation. The challenge requires to create permutations based on a string and then count the ones that don’t have the same letter followed by each other.

Basically, here is my code. I’ve been making several revisions already but just can’t wrap my head around it. I feel as if I’m very close yet can’t seem to figure out the next possible step:

function permAlone(str) {
var strArr = str.split(’’);

strArr.filter(function(charUsed, index) {
var ch = charUsed; // Store charUsed in a variable
var subPerm = strArr.slice(0); // Create shallow copy of strArr
var temp, dest = [];

``````subPerm.splice(index, 1);  // Get sub-permutation where charUsed is removed
``````

// console.log(charUsed);
// console.log(subPerm);
for (var i = 0; i <= subPerm.length; ++i) {
temp = subPerm.slice(0); // Copy the array
temp.splice(i, 0, ch); // Insert the new character
dest.push(temp);
}
console.log(dest);

});
console.log(‘end’);
}

I’ve been trying to figure out both the recursive example from this link in freecodecamp and the non-recursive but so far, im don’t know how to get what I’m supposed to have as a result (permutation only, no duplicate char filtering). This example is currently the non-recursive and I’m getting results with the parameter (a, a, b).

So far, my results are these [[a,a,b], [a,a,b], [a,b,a]], [[a,a,b], [a,a,b], [a,b,a]], [[b,a,a], [a,b,a], [a,a,b]]. So as everyone can see, far from the expected results of (aab, aab, aba, aba, baa, baa). Can anyone help me figure out what i seem to be missing? Thanks!