|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
588 bytes
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = reduce;
|
|---|
| 7 | function reduce(values, reducer, value) {
|
|---|
| 8 | if (typeof reducer !== "function") throw new TypeError("reducer is not a function");
|
|---|
| 9 | const iterator = values[Symbol.iterator]();
|
|---|
| 10 | let done,
|
|---|
| 11 | next,
|
|---|
| 12 | index = -1;
|
|---|
| 13 | if (arguments.length < 3) {
|
|---|
| 14 | ({
|
|---|
| 15 | done,
|
|---|
| 16 | value
|
|---|
| 17 | } = iterator.next());
|
|---|
| 18 | if (done) return;
|
|---|
| 19 | ++index;
|
|---|
| 20 | }
|
|---|
| 21 | while (({
|
|---|
| 22 | done,
|
|---|
| 23 | value: next
|
|---|
| 24 | } = iterator.next()), !done) {
|
|---|
| 25 | value = reducer(value, next, ++index, values);
|
|---|
| 26 | }
|
|---|
| 27 | return value;
|
|---|
| 28 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.