Hi,

It’s been several days that I’m stuck with this challenge. I tried to use Heap’s algorithm challenge but something seems to go wrong as my code doesn’t produce expected results (Missing some permutations ?).

```
function permAlone(str) {
var result = [], strArray = str.split(""), positionTemp;
console.log ("strArray : " + strArray);
function generate(n,strArray) {
if (n == 1) {
result.push(strArray.join(""));
} else {
for (i = 0, c = n - 1; i < c; i++) {
generate(n - 1, strArray);
if (n % 2 === 0){
positionTemp = strArray[i];
strArray[i] = strArray[n - 1];
strArray[n - 1] = positionTemp;
result.push(strArray.join(""));
} else {
positionTemp = strArray[0];
strArray[0] = strArray[n - 1];
strArray[n - 1] = positionTemp;
result.push(strArray.join(""));
}
}
generate(n - 1, strArray);
}
}
generate(strArray.length,strArray);
result = result.filter(function(obj){
if (/(.)\1/g.test(obj) !== true) {
return obj;
}
});
console.log("result final : " + result);
console.log("length result final : " + result.length);
console.log("---------------");
return result.length;
}
permAlone('aab');
```

What’s going wrong ? Could someone help me out ?