Skip to content

Instantly share code, notes, and snippets.

@NigelEarle
Created October 21, 2017 18:23
Show Gist options
  • Save NigelEarle/afa59904f2bc02fe2338f359460f2523 to your computer and use it in GitHub Desktop.
Save NigelEarle/afa59904f2bc02fe2338f359460f2523 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