Class Index | File Index

Classes


Function Namespace Pot.reduce


Defined in: <potlite.js>.

Function Namespace Summary
Constructor Attributes Constructor Name and Description
 
Pot.reduce(object, callback, initial, (context))
Apply a function against an accumulator and each value of the object (from left-to-right) as to reduce it to a single value.
Function Namespace Detail
Pot.reduce(object, callback, initial, (context))
Apply a function against an accumulator and each value of the object (from left-to-right) as to reduce it to a single value. This method like Array.prototype.reduce
  var array = [1, 2, 3, 4, 5];
  var total = Pot.reduce(array, function(a, b) { return a + b; });
  debug(total);
  // @results 15
  var object = {a: 1, b: 2, c: 3};
  var total = Pot.reduce(object, function(a, b) { return a + b; });
  debug(total);
  // @results 6
Parameters:
{Array|Object|*} object
A target object.
{Function} callback
A callback function.
{*} initial
An initial value passed as `callback` argument that will be used on first iteration.
{*} (context)
(Optional) Object to use as the first argument to the first call of the `callback`.
Returns:
{*} Return the result of each callbacks.

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Sep 21 2012 19:35:45 GMT+0900 (JST)