Skip to content

Instantly share code, notes, and snippets.

@Nicknyr
Last active October 10, 2018 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nicknyr/17e84cc77b74e7dee351d7dfa298b83f to your computer and use it in GitHub Desktop.
Save Nicknyr/17e84cc77b74e7dee351d7dfa298b83f to your computer and use it in GitHub Desktop.
Javascript Palindrone - Turn string into array and then use .reverse method to compare
function isPalindrone(word) {
// This approach converts the string into an array and then reverses it
// Split splits the string into an array, each letter of the word is it's own array element
// Reverse reverses the array elements but they are still separate characters spaced out
// Join squishes the letters back into be one solid word without spaces between characters
let reversed = word.split('').reverse().join('');
// Compare orginal word to reversed word
if( word == reversed) {
return true;
}
else {
return false;
}
}
console.log(isPalindrone('racecar'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment