23 ms·
I don't think isEmpty is O(n) except in the case where the object is a prototype[1] - I assume that's one of those weird JS edge cases - otherwise it does what
by mediumdeviation 3y ago
I don't think isEmpty is O(n) except in the case where the object is a prototype[1] - I assume that's one of those weird JS edge cases - otherwise it does what you expect, which is to iterate with a for-in loop and return on the first iteration, so it is O(1).
[1]: https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L11493 https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L114...
- paulgb 3y agoSurprisingly, even if you return at the first iteration, it’s O(n) on V8 just to construct the iterator.