Palindrome Challenge - My solution - Feeling humbled

This challenge was the first “challenging” one so far. After I came up with a working solution I went back and read the “hint” section to try to find different ways to accomplish it. I see that I used some extra variables and could have combined the split, reverse, join methods.

This challenge took around 3 hours and it kicked my behind…
I guess I would register this as a basic solution from looking at the examples.

function palindrome(str) {
  var lowerCase = str.toLocaleLowerCase().replace(/[^A-Z0-9]+/ig, '');
  var splited = lowerCase.split('');
  var reversed = splited.reverse();
  var joined = reversed.join('').replace(/[^A-Z0-9]+/ig, '');
      
  var a = lowerCase;
  var b = joined;
 
 if (a !== b){
    return false;
  }else{
    return true;
  }   
}

palindrome("eYe");

But you did it. That’s the goal. You’ve even analyzed how you can improve your code. Things are looking good.

1 Like