[Advanced Algorithm Scripting] No repeats please - Returns are correct, but not accepted. FCC doesn't want me to do it this way?[Spoiler alert]

[Advanced Algorithm Scripting] No repeats please - Returns are correct, but not accepted. FCC doesn't want me to do it this way?[Spoiler alert]
0

#1

Hey Campers,

So I’m doing this “No repeats please” challenge, I did the regexp part on my own, i knew what am i looking for, but couldn’t do the permutations part, so I copied a snippet (it was a tough decision made after about 10 hours with that exercise).

Now I get all the tests passed, but it is not accepted by freecodecamp. I assume the system didn’t want me to do it this way. (?) What’s my sin here?

I would appreciate not giving straight forward answers, or working code examples. With your help, advice, i would like to give myself another shot with this

https://jsfiddle.net/Rycerz_Andromedy/g76sf95j/3/

var regexp = /(.)\1+/gi;  // pattern is: any sign followed by at least one the same sign
var permArr = [], usedChars = [];
// PERMUTATING FUNCTION
function permutate(str) {
var i, ch, chars = str.split("");
for (i = 0; i < chars.length; i++) {
	ch = chars.splice(i, 1);
  usedChars.push(ch);
  if (chars.length == 0) permArr[permArr.length] = usedChars.join("");
  permutate(chars.join(""));
  chars.splice(i, 0, ch);
  usedChars.pop();
}
return permArr;
}
// MAIN FUNCTION
function permAlone (str) {
filter = permutate(str);
counter = 0;
for (var j = 0; j < filter.length; j++) {
if (filter[j].match(regexp) === null) { // if pattern's match returns null ->there are no consecutive letters
counter++;
}
}
return counter;
}
// TEST
permAlone("abcdefa");
console.log(counter);

#2

I don’t wanna peek at the code as I haven’t passed it yet, but if you’re passing all the tests, then you pass the challenge - FCC doesn’t look for a particular solution, just that the tests pass.

What does the screen look like when you submit your solution?

Does the error console reveal any problems?


#3

Nope, the console returns the wanted values. But it’s all red.

// I meant that I get correct results, both on jsfiddle with console, and in the console on fcc.


#4

Is there a stray piece of white space being thrown into the mix? I had that problem on a couple of earlier algorithms when I concatenated strings that popped an extra space on the end.

I’d give more specific advice, but I’m really avoiding actually looking at the code! Blindfolded bug hunting :slight_smile:


#5

I don’t actually know what do you mean, and where to look for that white space (?)
Thanks for help, but i think you’ve got to look at it to make any conclusions : )

I tried to return typeof result. It’s a number type. So if the results are correct, and the type also is…

I wonder whether somebody who did this one already could post his comment :slight_smile:

BECAUSE IT DOES NOT WORK GRRRRRRRRRRRRRRRRFAWT@$T$t :stuck_out_tongue:


#6

I’ve just checked the challenge and it doesn’t require whitespace :slight_smile: So I’ll stop offering dud suggestions and take a look properly :slight_smile:


#7

I’ve been debugging it with a few console logs and found some odd behaviour.

If you try to console log the permArr and run the test the number of permutations it spits out is way too high. I actually crashed my browser. I’ll keep digging…

Edit

This may be a red herring - see below


#8

Ok, here’s some hints:

You have declared some of your variables outside of the scope you intend to use them in - when these hit the tests, they behave in ways you didn’t expect.

You have also set some variables as globals, which again leads to unexpected behaviours.

I haven’t passed all of the tests yet, using your code, but by cleaning yours up with properly decalred variables in the right places, half of them now pass. The half that don’t pass all seem to return 0


#10

thanks for your time, really appreciated :slight_smile:


#11

thanks for help, i really appreciate it :slight_smile: