MCPcopy Create free account
hub / github.com/careercup/CtCI-6th-Edition-JavaScript / palinPerm

Function palinPerm

chapter01/1.4 - PalinPerm/palinPerm2.js:1–16  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

1function 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
19console.log(palinPerm('Tact Coa'), 'true');

Callers 1

palinPerm2.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected