Created
May 26, 2020 21:29
-
-
Save marshallmurphy/1ffd68f6271afa6806e13486168cfbe9 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 palindromePermutation(inputString) { | |
// create a set to track characters we've seen | |
const charSet = new Set(); | |
// iterate over each character by spitting into an array | |
inputString.split('').forEach(char => { | |
// remove from set if previously added | |
if (charSet.has(char)) { | |
charSet.delete(char); | |
// add to set if not already present in set | |
} else { | |
charSet.add(char) | |
} | |
}) | |
// set should have 0 or 1 entry if is a palindrome | |
return charSet.size <= 1; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment