Skip to content

Instantly share code, notes, and snippets.

@imkrish
Created November 18, 2019 08:47
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 imkrish/cc377c05332e26fec051e08bff99ce30 to your computer and use it in GitHub Desktop.
Save imkrish/cc377c05332e26fec051e08bff99ce30 to your computer and use it in GitHub Desktop.
//Make the following test cases pass
function isPalindrome(phrase) {
const SPACE = " ";
const lowerCharsInPhrase = phrase
.toLowerCase()
.split("")
.filter(char => char !== SPACE);
return lowerCharsInPhrase.join() === lowerCharsInPhrase.reverse().join();
}
function check(phrase, shouldBePalindrome) {
console.log(isPalindrome(phrase) === shouldBePalindrome ? "PASS" : "FAIL");
}
check("abcba", true);
check("abcde", false);
check("Mr owl ate my metal worm", true);
check("Never Odd Or Even", true);
check("Never Even Or Odd", false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment