Message from JavaScript discussions

May 2017

— It is a linear search... we can either use some more optimized search algorithm, maybe further refining the set's structure, or just remove it completely and not have any idea how many items are in the set

Message permanent page

— 

I mean, you could count manually, of course... but you would have to do that externally because only the caller would know how many times they called add when the string already existed in the set

— But that's not even reliable because the caller might not know that either, it would be just as costly to implement outside the class as it would be inside

Message permanent page

— Maybe instead there can just be a length method which sums the array lengths

— 

this.length = function () {
var sum = 0;
for (var set in list) {
for (var subset in character) {
sum += subset.length;
}
}
return sum;
};

Message permanent page

— A friend of mine reccomended trying prime divisibility instead of uniques

— IE assign each character to a prime number, then test strings for divisibility somehow

— If divisibility fails, then the word has definitely not been added.

— That would be a lot faster than doing the linear search, I think

— Oooh shit, got it down to 126ms using indexOf instead of includes

— But it might be browser-specific https://jsperf.com/array-indexof-vs-includes

— Hmm