Last active
March 8, 2017 23:58
-
-
Save nealfennimore/4b9885f15a830753272d141f834d950b to your computer and use it in GitHub Desktop.
Palindrome Permutation
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 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