Skip to content

Instantly share code, notes, and snippets.

@Luke-Rogerson
Created December 9, 2018 16:47
Show Gist options
  • Save Luke-Rogerson/353780e049ea35ec3804284ecdb8519b to your computer and use it in GitHub Desktop.
Save Luke-Rogerson/353780e049ea35ec3804284ecdb8519b to your computer and use it in GitHub Desktop.
Palindrome
// --- 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