Created
September 24, 2015 23:22
-
-
Save Ianfeather/ea9e584b2d5db075b541 to your computer and use it in GitHub Desktop.
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
function couldBePalindromic(word) { | |
let letters = word.split(''); | |
let matches = letters.map(letter => { | |
// How many sets of characters are multiples of 2 | |
return letters.filter((l) => l == letter).length % 2 == 0 | |
}) | |
// Filter out the ones that aren't | |
.filter((bool) => bool == true) | |
// If the word is even they should all be true, otherwise only one should be false | |
return matches.length == (word.length % 2 == 0 ? letters.length : letters.length - 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment