Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Last active May 3, 2021 14:59
Show Gist options
  • Save nathansmith/4347684 to your computer and use it in GitHub Desktop.
Save nathansmith/4347684 to your computer and use it in GitHub Desktop.
Just a pointless JS snippet to test if a word is a palindrome.
function isPalindrome(str = '') {
return str === String(str).split('').reverse().join('');
}
/*
// Example usage…
// Logs `true`.
isPalindrome('racecar');
// Logs `true`.
isPalindrome(45654);
// Logs `false`.
isPalindrome('hello');
// Logs `false`.
isPalindrome(12345);
*/
@nathansmith
Copy link
Author

For further pointlessness, see this string reversal benchmark test…

http://jsperf.com/is-palindrome

So awesome! :)


// Benchmark made by @getify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment