DEV Community

Discussion on: The Holy Trinity of Functional Programming: Map, Filter and Reduce

Collapse
 
morgboer profile image
Riaan Pietersen • Edited

Great succinct article, Mikhail, thank you for writing it.

Question about your .filter example.
You say that using .filter will loop through everything and create another array that contains the result set.
Then, in the forloop example, you are creating a separate array in any case (const result: User[] = []).

As I see it your forloop approach should avoid creating another array - right? What would the approach be to not create a result set array?
In the past I have avoided creating a duplicate by slicing the unmatched value out of the original array. Would that work?