Juan Cruz Martinez
1 min readJul 16, 2020

--

Hi Lynn, it does depend, some methods like map, every, reduce, filter, forEach have a minimum complexity of O(n); however, it could depend on what you do inside.

Other methods like sort, are more complex as they depend on the implementation. JavaScript does not specify how you resolve the sort function, so depending on the JavaScript engine you may have different complexities (at least in theory).

I believe V8, which is the JS engine for Chrome and Node, uses quicksort, so the minimum time complexity would be O(n log(n)). at least for bigger arrays, for smaller arrays, it may use a different algorithm.

I hope this answers a bit of your question. I’d like to go deeper into the topic, but its a major thing and would require to analyze a specific implementation. But if you have an specific question in one of those, please let me know.

--

--

Juan Cruz Martinez

I stream, blog, and make youtube videos about tech stuff. I love coding, I love React, and I love building stuff!