"Palindrome Checker" bug

"Palindrome Checker" bug
0

#1

I tried it in the browser console and node.js and it works but for some reason freeCodeCamp can’t test this (the flasks don’t change into anything)


"use strict";
const normalize = function normalize(x) {return x.match(/\w/g).join('').toUpperCase();};
const isPalindrome = function isPalindrome(a,equal = (a,b) => a===b) {
  for(let s=0,e=a.length-1;s<e;s++,e--) if (!equal(a[s],a[e])) return false;
  return true; 
};
function palindrome(str) {
  return isPalindrome(normalize(str));
};



palindrome("eye");

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker


#2

Wrapping the for loop with braces will at least fix code not running. Don’t ask me why I don’t know how the issue was created at the first place.

for(let s = 0, e = a.length - 1; s < e; s++, e--) {
    if (!equal(a[s],a[e]))
        return false
}

Bad news is that your code still won’t pass the test.

As a side note:
You should really learn how to indent your code if you want others to read your code.

Why declare the name of function two times?

You also don’t have to pre-compute the length during the initialization of the for loop. If you are concerned with performance, then this difference is insignificant and any underlying JS engine will likely to optimize things like this before you do.