Created
October 21, 2017 18:23
-
-
Save NigelEarle/afa59904f2bc02fe2338f359460f2523 to your computer and use it in GitHub Desktop.
Array of palindromes
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
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