3 ms·
You would think, right? The JS runtime itself must have a constant time way to know this, but it’s not exposed anywhere. The best you can do is iterate over th
by paulgb 2y ago
You would think, right?
The JS runtime itself must have a constant time way to know this, but it’s not exposed anywhere. The best you can do is iterate over the keys and bail the first time you get a key. But (at least in V8) iterating over the keys does some work up front that is O(n), even if you bail at the first key!
- patates 2y agoI think the issue is that the arrays are allowed to have holes: test = new Array(2) -> Array [ <2 empty slots> ] test[1] = true -> true test.length -> 2 test[0] -> undefined test[3] -> undefined test.some(x => x) -> true delete test[1] -> true test.some(x => x) -> false