Skip to content

Instantly share code, notes, and snippets.

@marshallmurphy
Created May 26, 2020 21:29
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 marshallmurphy/1ffd68f6271afa6806e13486168cfbe9 to your computer and use it in GitHub Desktop.
Save marshallmurphy/1ffd68f6271afa6806e13486168cfbe9 to your computer and use it in GitHub Desktop.
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