Skip to content

Commit 96b534f

Browse files
authored
feat: added another answer for chp.1 q4 (careercup#66)
1 parent 47d7a9c commit 96b534f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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');
20+
console.log(palinPerm('Tact boa'), 'false');

0 commit comments

Comments
 (0)