Skip to content

Instantly share code, notes, and snippets.

@darshna09
Last active April 19, 2021 09:21
Show Gist options
  • Save darshna09/68591b2168f302d122e16421ee439e2c to your computer and use it in GitHub Desktop.
Save darshna09/68591b2168f302d122e16421ee439e2c to your computer and use it in GitHub Desktop.
Check if the given word is a palindrome or not.
/**
* @param {string} word
* @return {boolean}
* true if palindrome else false
*/
function isPalindrome (word) {
if (word) {
return word.toLowerCase() === word.toLowerCase().split('').reverse().join('') ? true : false;
} else {
return false;
}
}
isPalindrome('radar'); // true
isPalindrome('RadAr'); // true
isPalindrome('No'); // false
isPalindrome(); // false
isPalindrome('#$#'); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment