Module 7 · Arrays and the Array Methods: The map, filter, reduce Pipeline
When to Use the Pipeline, When to Use a Loop, and How to Choose
Free with an accountReading
Kenji has just learned map, filter and reduce, and now he writes everything as a pipeline. His code review comes back with two comments. One says "this reduce is very hard to follow, please use a loop". The other, on a different file, says "this loop is four lines of bookkeeping, please use filter". Kenji is confused. Which one is right?
Checking what this lesson needs for you…
What is inside When to Use the Pipeline, When to Use a Loop, and How to Choose
- Readability first
- A loop against the pipeline: a measured run
- map against forEach
- reduce against a loop
- When the loop wins: stopping early and carrying state
- The comparison table