These are chat archives for camperbot/bonfire-check-for-palindromes

10th
Sep 2015
Joseph odhiambo
@Theonlysmartboy
Sep 10 2015 10:03
Hint
CamperBot
@camperbot
Sep 10 2015 10:03

hint [8/8]

Second

function palindrome(str) {
  str = str.toLowerCase().replace(/[\W_]/g, '');
  for(var i = 0, len = str.length - 1; i < len/2; i++) {
    if(str[i] !== str[len-i]) {
      return false;
    }
  }
  return true;
}

Code Explanation:

We use regular expressions to replace any uppercase letter into a lowercase. Then we check if the string is the same as the reversed string using split() to split the original string by characters, then reverse and then join it back together.

Credits:

If you found this page useful, you can give thanks by copying and pasting this on the main chat: Thanks @Rafase282 @abhisekp

type hint for next hint :pencil: [Contribute at the FCC Wiki]