3 ms·
Yes, but this will still filter through all the items, instead of stopping at 5.
by dsego 5y ago
Yes, but this will still filter through all the items, instead of stopping at 5.
- darepublic 5y agoI 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.
- dsego 5y agoIt 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.
- darepublic 5y agoah, yeah you are right.