@ndhoule/foldl

Apply a function to each value in a collection, accumulating the results into a single return value.

foldl

Apply a function to each value in a collection, accumulating the results into a single return value.

Installation

$ component install ndhoule/foldl
$ npm install @ndhoule/foldl

API

reduce(iterator : Function, accumulator : *, collection : Array|Object)

Reduces all the values in a collection down into a single value. Does so by iterating through the collection from left to right, repeatedly calling an iteratorfunction and passing to it four arguments: (accumulator, value, index, collection).

foldl(function(total, n) {
  return total + n;
}, 0, [1, 2, 3]);
//=> 6

var phonebook = { bob: '555-111-2345', tim: '655-222-6789', sheila: '655-333-1298' };

foldl(function(results, phoneNumber) {
 if (phoneNumber[0] === '6') {
   return results.concat(phoneNumber);
 }
 return results;
}, [], phonebook);
// => ['655-222-6789', '655-333-1298']

License

Released under the MIT license.

HomePage

https://github.com/ndhoule/foldl

Repository

https://github.com/ndhoule/foldl.git


上一篇:@ndhoule/includes
下一篇:@ndhoule/extend

相关推荐

  • @ndhoule/rest

    Produce a new array composed of all but the first element of the input collection. rest CIcibadgec...

    6 个月前
  • @ndhoule/pick

    Create a shallow copy of an input object that contains only the specified properties. pick CIcibad...

    7 个月前
  • @ndhoule/map

    Apply a function to a each element of a collection and return a new array of results. map CIcibadg...

    7 个月前
  • @ndhoule/keys

    Create an array of the owned/enumerable keys of an input object. keys CIcibadgecilink Create an a...

    7 个月前
  • @ndhoule/includes

    Determine whether or not a value is contained by a given collection. includes CIcibadgecilink Det...

    7 个月前
  • @ndhoule/extend

    Extend an object with the properties of another. extend CIcibadgecilink Extend an object with the...

    7 个月前
  • @ndhoule/every

    Check if a function returns true for all values in a . every CIcibadgecilink Check if a functio...

    6 个月前
  • @ndhoule/each

    Iterate over a collection, invoking a function for each element. each CIcibadgecilink Iterate ove...

    7 个月前
  • @ndhoule/drop

    Produce a new array composed of all but the first n elements of an input collection. drop CIcibadg...

    6 个月前
  • @ndhoule/defaults

    Copies owned, enumerable properties from a source object(s) to a target object when the value of tha...

    7 个月前

官方社区

扫码加入 JavaScript 社区