Skip to content

Collection Methods

sergio edited this page Nov 10, 2020 · 6 revisions

MDN list

Process a collection by visiting each element and do "work" (function()) on it in order to return a new collection or an aggregate value.

map methods return a new Array. reduce methods return a value.

Map (transformer)

we're going to produce a new Array after "transforming" or applying "work" to each element. "Map" comes from mathematics where it means:

  • Taking an independent variable
  • Plugging it into an equation
  • Getting a result back

Mathematicians would say you're mapping a value in the domain to a value in the range.

Reduce (aggregator)

we start with an initial value that we'll call the "memo" or "aggregator." Then we do some "work" involving the element and the "aggregator" and that work updates the "aggregator".

Clone this wiki locally