@ndhoule/foldl

2020-01-13

@ndhoule/foldl

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

ci">foldl CI

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.

以上是 @ndhoule/foldl 的使用教程帮助文档。


上一篇:@ndhoule/includes
下一篇:@ndhoule/extend
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章
暂无相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部