diff --git a/chapter01/1.1 - Is Unique/isUnique.js b/chapter01/1.1 - Is Unique/isUnique.js index 136496c..002644e 100644 --- a/chapter01/1.1 - Is Unique/isUnique.js +++ b/chapter01/1.1 - Is Unique/isUnique.js @@ -12,5 +12,19 @@ var allUniqueChars = function(string) { return true; // if no match, return true }; +const everyCharUnique = (str, indexOffset = 'a'.charCodeAt()) => { + let counterTable = Number(); + for(let index of [...str].map(c => c.charCodeAt() - indexOffset)) { + const mask = 1 << index; + if(counterTable & mask) + return false; + counterTable |= mask; + } + return true; +}; + /* TESTS */ -// log some tests here \ No newline at end of file +console.log(everyCharUnique('abcd'), 'true'); +console.log(everyCharUnique('abccd'), 'false'); +console.log(everyCharUnique('bhjjb'), 'false'); +console.log(everyCharUnique('mdjq'), 'true');