Alright, I’ve got it for reals this time. I’m not sure *why* this is the case just yet (which is bugging me to no end), but we can make just two, simple change from your original code:

```
if (n === 1) {
output.push(array.join(''));
}
//later
array.forEach(function(el) {
// remove the join() call here
if (!el.match(regex)) counter++;
});
```

I agree that this seems to be a scoping issue, but I don’t have an answer as to why your code didn’t work.

Full code:

```
function permAlone(str) {
var arr = str.split('');
var perms = [];
permutation(arr, arr.length, perms);
var result = checkRepeating(perms);
return result;
}
var swap = function(array, pos1, pos2) {
var tmp = array[pos1];
array[pos1] = array[pos2];
array[pos2] = tmp;
};
var permutation = function(array, n, output) {
if (n === 1) {
output.push(array.join(''));
} else {
for (var i = 0; i < n - 1; i++) {
permutation(array, n - 1, output);
n % 2 ? swap(array, 0, n - 1) : swap(array, i, n - 1);
}
permutation(array, n - 1, output);
}
};
var checkRepeating = function(array) {
var regex = /(.)\1/;
var counter = 0;
array.forEach(function(el) {
if (!el.match(regex)) counter++;
});
return counter;
};
permAlone("aab");
```