We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 47d7a9c commit 96b534fCopy full SHA for 96b534f
chapter01/1.4 - PalinPerm/palinPerm2.js
@@ -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