Skip to content

Instantly share code, notes, and snippets.

@nblackburn
Last active November 5, 2024 22:27
Show Gist options
  • Save nblackburn/6f41e0596ef1d5e15d59de4e796ea84c to your computer and use it in GitHub Desktop.
Save nblackburn/6f41e0596ef1d5e15d59de4e796ea84c to your computer and use it in GitHub Desktop.
Is Palindrome

Checks if a given word is a palindrome.

Usage

const tests = ['hannah', 'anna', 'kayak', 'apple', 'mom', 'wow', 'rotator', 'radar']

tests.forEach((test) => {
    console.log('IS_PALINDROME', test, isPalindrome(test));
});
const isPalindrome = (value) => {
const chars = value.replace(/[^a-zA-Z0-9]/g, '').toLowerCase().split('');
for (let index = 0; index < chars.length / 2; index++) {
if (chars[index] !== chars[chars.length - 1 - index]) {
return false;
}
}
return true;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment