Filter is just the wrong tool for the job. Use a reduce() instead.
Map: convert one elements of an array to an array of something else
Filter: create a new array with certain items removed
Reduce: compute something with the elements of an array
In Smalltalk these were called: collect, select/reject, inject:into: (I like those names better).
Filter is just the wrong tool for the job. Use a reduce() instead.
Map: convert one elements of an array to an array of something else
Filter: create a new array with certain items removed
Reduce: compute something with the elements of an array
In Smalltalk these were called: collect, select/reject, inject:into: (I like those names better).
martinfowler.com/articles/collecti...