# Determine whether any permutation of a string is a palindrome

Given a string, determine whether any permutation of it is a palindrome.

For example, "carrace" should return true, since it can be rearranged to form "racecar", which is a palindrome. "daily" should return false, since there's no rearrangement that can form a palindrome.

My solution:

const isPalindrome = str => {
const letterOccurrences = str
.split("")
.reduce((acc, x) => {
acc[x] = acc[x] ? acc[x] + 1 : 1;
return acc;
}, {});

let numberOfOddOccurrences = 0;
const isMaxOneOddNumberLetter = x => x % 2 === 0 || ++numberOfOddOccurrences <= 1;
return Object.values(letterOccurrences).every(isMaxOneOddNumberLetter);
};

console.log(isPalindrome("carrace"));


Is it possible to write the function isMaxOneOddNumberLetter without mutation resp. side effects?

const isPalindrome = s => s.split("").reduce(