Right answers, but not "passing"

I have completed No Repeats Please, and am getting the right answer for each example given. However, FCC is not recognizing that I’ve “passed”…? I’m not sure if it’s kosher to paste code here. Any ideas from anyone?

Halp.

Yes, please paste code. Also, keep in mind the internet was ddosed today, that may be affecting solutions passing.

Thank you!

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

var bigArray = [];

function permAlone(str){
  var array = str.split('');
  var c = heap(array, print);
  return c;
}

var heap = function (array, output, n) {
  var n = n || array.length; // set n default to array.length
  if (n === 1) {
    output(array);
    //bigArray.push(array);
  } else {
    for (var i = 1; i <= n; i += 1) {
      heap(array, output, n - 1);
      if (n % 2) {
        var j = 1;
      } else {
        var j = i;
      }
      swap(array, j - 1, n - 1); // -1 to account for javascript zero-indexing
    }
  }
  
  if(n===array.length){
    var c = bigArray.length-counterfunction();
    return c;
  }
};


// For testing:
var print = function(input){
  //console.log(input);
  var copy = input.slice();
  bigArray.push(copy);
};

//heap(['a', 'a', 'a'], print);
//console.log(bigArray);

function counterfunction(){
  var counter = 0;
  for(i=0; i<bigArray.length; i++){
    for(j=0; j<bigArray[0].length; j++ ){
      if(j !=0){
        if(bigArray[i][j]===bigArray[i][j-1]){
          counter = counter + 1;
          break;
        }
      }
    }
  }
  return counter;
}

permAlone("aaa");

Hi, Isaac, I actually figured it out! I think FCC was keeping the value of BigArray between function calls so it was messing up subsequent calls. I just had to clear the array before returning. :slight_smile:

1 Like

Just to add some clarification - FCC wasn’t keeping the value of BigArray. You were. BigArray was declared as a global variable, so its values persist between function calls.

I bet if you reviewed the challenges on global vs. local scope now they would make more sense and sink in better. Learning to program often involves going back to basics with fresh perspective.

1 Like