Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Significantly improved isValid performance.
Older implementation relied on iterating over each character of id(M) and every time searching for that character in alphabet(N). O(M * N), which seemed not too fast. Rewritten it to use regular expressions, which boosted performance. Here is the benchmark - https://jsperf.com/regex-vs-indexof-in-loop-2312 Used 1000 different generated ids, half of them were incorrect. On average, the current algorithm would score ~1.3k op/sec On the other hand, the new one makes around ~12.5k op/sec Which I've found significant enough to make a PR.
- Loading branch information