Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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#L114...



Surprisingly, even if you return at the first iteration, it’s O(n) on V8 just to construct the iterator.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: