3 ms·
Downside: Still going over the array multiple times.
by chris_st 7y ago
Downside: Still going over the array multiple times.
- agumonkey 7y agofair point, in js it will, in other languages that idiom gets deforested into a single pass though
- sli 7y agoYou could (usually, but not always) compose the functions you're passing into filter and map and use reduce instead to do both operations in a single pass. (Edit: This is a big point in the article -- apologies, I hadn't finished reading it yet.)