Skip to content

Instantly share code, notes, and snippets.

@Ianfeather
Created September 24, 2015 23:22
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 Ianfeather/ea9e584b2d5db075b541 to your computer and use it in GitHub Desktop.
Save Ianfeather/ea9e584b2d5db075b541 to your computer and use it in GitHub Desktop.
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