ga-wdi-boston / js-array-iteration-methods

JavaScript Array methods
Other
1 stars 160 forks source link

Mnemonics for `reduce` and/or `inject` #1

Closed jrhorn424 closed 8 years ago

jrhorn424 commented 9 years ago

In ruby, inject can be remembered because the operator (or block) is "injected" between items in the enumerable.

In JavaScript, we can remember reduce since it takes a set of many items and "reduces" them to a single value. For example:

var sum = function sum (a, b) {
  return a + b;
};

[1,2,3].reduce(sum,0) //=> 6
laurenfazah commented 8 years ago

This language is incorporated into the reduce section of the readme @jrhorn424 if you'd like to close

jrhorn424 commented 8 years ago

Thanks @laurenfazah!