Skip to content

Instantly share code, notes, and snippets.

@nealfennimore
Last active March 8, 2017 23:58
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 nealfennimore/4b9885f15a830753272d141f834d950b to your computer and use it in GitHub Desktop.
Save nealfennimore/4b9885f15a830753272d141f834d950b to your computer and use it in GitHub Desktop.
Palindrome Permutation
function palindrome(str){
const unique = [...new Set(str.split(''))];
const counts = unique.map( char =>{
return str.match( new RegExp(char, 'g') ).length
});
let odd = 0,
even = 0;
counts.forEach( count => count % 2 === 0 ? even += 1 : odd += 1 );
return odd <= 1 && (str.length - odd) / 2 === even;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment