(s)
| 1 | function palinPerm(s) { |
| 2 | const sanitized = s.toUpperCase().split(" ").join(""); |
| 3 | const freq = new Map(); |
| 4 | for (let i = 0; i < sanitized.length; i++) { |
| 5 | const char = sanitized.charAt(i); |
| 6 | const prevFreq = freq.get(char) || 0; |
| 7 | freq.set(char, prevFreq + 1); |
| 8 | } |
| 9 | let oddCount = 0; |
| 10 | for (let char of freq) { |
| 11 | if (char[1] % 2 !== 0) { |
| 12 | oddCount++; |
| 13 | } |
| 14 | } |
| 15 | return oddCount < 2; |
| 16 | } |
| 17 | |
| 18 | // TESTS |
| 19 | console.log(palinPerm('Tact Coa'), 'true'); |