Skip to content

Instantly share code, notes, and snippets.

@radiumrasheed
Forked from NigelEarle/palindrome.js
Created June 17, 2019 12:16
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 radiumrasheed/f639cc098f9aee7939b63a35e5ee35e2 to your computer and use it in GitHub Desktop.
Save radiumrasheed/f639cc098f9aee7939b63a35e5ee35e2 to your computer and use it in GitHub Desktop.
Array of palindromes
const arr = ['mom', 'dad', 'abcde', 'racecar', 'momom'];
function namePalindrome(arr) {
return arr.filter((curr, idx, arr) => {
const splitArr = curr.split('');
const reversedString = splitArr.reduceRight((prev, curr) => ( prev + curr ), '');
if (curr === reversedString) return curr;
})
}
namePalindrome(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment