-
-
Save radiumrasheed/f639cc098f9aee7939b63a35e5ee35e2 to your computer and use it in GitHub Desktop.
Array of palindromes
This file contains hidden or 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
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