Created
June 15, 2021 20:04
-
-
Save Elijah-trillionz/6c5f5f46bcae52abed8f067b72af4550 to your computer and use it in GitHub Desktop.
Palindrome Checker LVL 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkForPalindrome(phrase) { | |
const phraseInArr = phrase.split(''); | |
const noWhiteSpace = phraseInArr.filter((phrase) => { | |
return phrase !== ' '; // you can use regex to ignore characters | |
}); | |
const toUseLength = Math.floor(noWhiteSpace.length / 2); | |
const firstSet = noWhiteSpace.slice(0, toUseLength).join('').toLowerCase(); | |
const lastSet = noWhiteSpace | |
.slice(-toUseLength) | |
.reverse() | |
.join('') | |
.toLowerCase(); | |
if (firstSet === lastSet) return "It's palindrome"; | |
else return 'not palindrome'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment