Created
December 9, 2018 16:47
-
-
Save Luke-Rogerson/353780e049ea35ec3804284ecdb8519b to your computer and use it in GitHub Desktop.
Palindrome
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
// --- Directions | |
// Given a string, return true if the string is a palindrome | |
// or false if it is not. Palindromes are strings that | |
// form the same word if it is reversed. *Do* include spaces | |
// and punctuation in determining if the string is a palindrome. | |
// --- Examples: | |
// palindrome("abba") === true | |
// palindrome("abcdefg") === false | |
function palindrome(str) { | |
return str.split('').every((char, i) => char === str[str.length - 1 - i]); | |
// OR | |
// const reversed = str.split('').reduce((rev, curr) => rev = curr + rev, ''); | |
// return str === reversed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment