Last active
March 18, 2017 09:12
-
-
Save ianmstew/90d7e2d283b013ad3a4dfb1db4f235ed 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 isPalindromePermutation(string) { | |
let counter = 0; | |
for (let i = 0; i < string.length; i++) { | |
const char = string[i]; | |
if (char === ' ') { | |
continue; | |
} | |
const charCodeNormalized = char.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0); | |
if (charCodeNormalized < 0 || charCodeNormalized > 25) { | |
throw new Error('Unexpected non English alphabet character: ' + char); | |
} | |
counter ^= 1 << charCodeNormalized; | |
} | |
return (counter & (counter - 1)) === 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment