Last active
August 23, 2018 18:31
-
-
Save imgsrc/ccb856c6ff514ee2213d5c3cbaaede92 to your computer and use it in GitHub Desktop.
isPalindrom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isPalindrome("racecar"); // true | |
isPalindrome("race Car"); // true | |
function isPalindrome(word) { | |
// Уберём все символы, не являющиеся буквами | |
var lettersOnly = word.toLowerCase().replace(/\s/g, ""); | |
// Сравним строку с её перевёрнутой версией | |
return lettersOnly === lettersOnly.split("").reverse().join(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment