Skip to content

Instantly share code, notes, and snippets.

@ianmstew
Last active March 18, 2017 09:12
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 ianmstew/90d7e2d283b013ad3a4dfb1db4f235ed to your computer and use it in GitHub Desktop.
Save ianmstew/90d7e2d283b013ad3a4dfb1db4f235ed to your computer and use it in GitHub Desktop.
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