Skip to content

Instantly share code, notes, and snippets.

@Elijah-trillionz
Created June 15, 2021 20:04
Show Gist options
  • Save Elijah-trillionz/6c5f5f46bcae52abed8f067b72af4550 to your computer and use it in GitHub Desktop.
Save Elijah-trillionz/6c5f5f46bcae52abed8f067b72af4550 to your computer and use it in GitHub Desktop.
Palindrome Checker LVL 1
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