Enumerable#reduce()

reduce (callback, initialValue, reducerProperty) Objectpublic

Defined in packages/ember-runtime/lib/mixins/enumerable.js:685

This will combine the values of the enumerator into a single value. It is a useful way to collect a summary value from an enumeration. This corresponds to the reduce() method defined in JavaScript 1.8.

The callback method you provide should have the following signature (all parameters are optional):

function(previousValue, item, index, enumerable);
  • previousValue is the value returned by the last call to the iterator.
  • item is the current item in the iteration.
  • index is the current index in the iteration.
  • enumerable is the enumerable object itself.

Return the new cumulative value.

In addition to the callback you can also pass an initialValue. An error will be raised if you do not pass an initial value and the enumerator is empty.

Note that unlike the other methods, this method does not allow you to pass a target object to set as this for the callback. It's part of the spec. Sorry.

Parameters:

callback Function
The callback to execute
initialValue Object
Initial value for the reduce
reducerProperty String
internal use only.

Returns:

Object
The reduced value.
doc_EmberJs
2016-11-30 16:52:00
Comments
Leave a Comment

Please login to continue.