Help! Problem: No Repeats Please

Tell us what’s happening:
I tested the code but it is not working

Your code so far


var permArr = [],
  usedChars = [];

function permute(input) {
  var i, char;
  for (i = 0; i < input.length; i++) {
    char = input.splice(i, 1)[0];
    usedChars.push(char);
    if (input.length == 0) {
      permArr.push(usedChars.slice());
    }
    permute(input);
    input.splice(i, 0, char);
    usedChars.pop();
  }
  return permArr;
};

function permAlone(str) {
  var count = 0;
  var repeat = false;
  var splited = str.split('');
  var permutations = permute(splited);

  for(let i = 0; i<permutations.length; i++){
    for(let j = 0; j<permutations[i].length; j++){
      if(permutations[i][j]==permutations[i][j+1]){
        repeat = true;
      }
    }
    if(!repeat){
      count++;
    }
    repeat = false;
  }

  return count;
}



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/algorithms/no-repeats-please

@hk4465ty,

please tell us why the code isn’t working. Have you tried debugging it? Using console.log statements to see what gets printed out? What test cases fail?

Provide us with more information so we can help you out.

If I understand correctly you are calculating all permutations and then counting those but not the duplicates.

You might do best to start with a simple case to determine which of those two steps is failing.

Log to the console to see the results of your calculations each step and compare those to the expected results.

You might do better to solve this in another environment like codepen or repl.it and then copying your final solution back into FCC editor for testing. You’ll be able to see the logged values without the interference of the assertion tests.