0 points

Palindrome Checker (FreeCodeCamp)


dashboard

Tue Aug 04 2020 19:25:25 GMT+0000 (UTC)

Posted by @ludaley #javascript #strings #arrays

function palindrome(str) {
    const alphanumericOnly = str
        // 1) Lowercase the input
        .toLowerCase()
        // 2) Strip out non-alphanumeric characters
        .match(/[a-z0-9]/g);
        
    // 3) return string === reversedString
    return alphanumericOnly.join('') ===
        alphanumericOnly.reverse().join('');
}



palindrome("eye");

content_copy Copy

https://www.freecodecamp.org/news/freecodecamp-palindrome-checker-walkthrough/