Skip to content

Comment on Lodash's Chain vs. Native Methodsparent

Comments

I don't see how lodash could possibly filter a list of 30 by a criteria without visiting each item at least once to take a look at it. the only way to make it more efficient would be to have lodash collect the desired transformations (filter/map) and then run a single loop over the items, mapping only those items that meet the filter criteria. But that is not much more efficient than the [].filter().map() that you could do with native methods.

It doesn't have to visit all 30 items, just enough items to take 5 from, could be 8, could be 10 etc. The lazy approach _is_ to collect all transformations and apply them in the end.

ah, yeah you are right.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.