Skip to content

Commit afc0084

Browse files
lopezpdvnprofnandaa
authored andcommitted
feat: 1.1 solution with bit array/vector & ES6 (careercup#44)
1 parent f04e7a4 commit afc0084

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

chapter01/1.1 - Is Unique/isUnique.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,19 @@ var allUniqueChars = function(string) {
1212
return true; // if no match, return true
1313
};
1414

15+
const everyCharUnique = (str, indexOffset = 'a'.charCodeAt()) => {
16+
let counterTable = Number();
17+
for(let index of [...str].map(c => c.charCodeAt() - indexOffset)) {
18+
const mask = 1 << index;
19+
if(counterTable & mask)
20+
return false;
21+
counterTable |= mask;
22+
}
23+
return true;
24+
};
25+
1526
/* TESTS */
16-
// log some tests here
27+
console.log(everyCharUnique('abcd'), 'true');
28+
console.log(everyCharUnique('abccd'), 'false');
29+
console.log(everyCharUnique('bhjjb'), 'false');
30+
console.log(everyCharUnique('mdjq'), 'true');

0 commit comments

Comments
 (0)