source: node_modules/d3-array/src/reduce.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 460 bytes
Line 
1export default function reduce(values, reducer, value) {
2 if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
3 const iterator = values[Symbol.iterator]();
4 let done, next, index = -1;
5 if (arguments.length < 3) {
6 ({done, value} = iterator.next());
7 if (done) return;
8 ++index;
9 }
10 while (({done, value: next} = iterator.next()), !done) {
11 value = reducer(value, next, ++index, values);
12 }
13 return value;
14}
Note: See TracBrowser for help on using the repository browser.