# Stuck running tests on No Repeats Please algorithm

I ran the code in FCC but it is stuck running the test. I assume its because there is a lot of recursion going on and there are too many calls on the stack.

The test cases all return the right results when i run them in repl.

How can I get past this issue and onto the next challenge? Do I have to refactor my code to a less expensive solution?

``````var permutations = [];

var duplicateTest = function(perm) {
const result = perm.filter(function(arr) {
var duplicateLtrTest = RegExp(/(\w)\1+/);
return !duplicateLtrTest.test(arr.join(''));
})
return result.length;
}

var swap = function (array, pos1, pos2) {
var temp = array[pos1];
array[pos1] = array[pos2];
array[pos2] = temp;
};

function permAlone (str, n) {
if (typeof str === 'string') {
str = str.split('');
}

n = n || str.length; // set n default to array.length
if (n === 1) {
// output(array);
permutations.push(Array.from(str));
var duplicateLtrTest = RegExp(/(\w)\1+/);
if (!duplicateLtrTest.test(str.join(''))) {
permutations.push(str);
}
} else {
for (var i = 1; i <= n; i += 1) {
permAlone(str, n - 1);

if (n % 2) {
var j = 1;
} else {
var j = i;
}
swap(str, j - 1, n - 1); // -1 to account for javascript zero-indexing
}
}

return duplicateTest(permutations)
};

permAlone('a');
// permAlone(['a', 'a', 'b', 'b']);
// heapsPermute([1, 2, 3], print)

``````

I tried your code and it fine worked for me. Possibly you need to clear local storage from a previous version of your code. Just a guess but worth a try.