|
Last change
on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
562 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | function reduce(set, callback, initialValue) {
|
|---|
| 6 | if (initialValue == null && set.size === 0) {
|
|---|
| 7 | throw new TypeError('Reduce of empty set with no initial value');
|
|---|
| 8 | }
|
|---|
| 9 | let accumulator = initialValue;
|
|---|
| 10 | for (const value of set) {
|
|---|
| 11 | if (accumulator == null) {
|
|---|
| 12 | accumulator = value;
|
|---|
| 13 | }
|
|---|
| 14 | else {
|
|---|
| 15 | accumulator = callback(accumulator, value, value, set);
|
|---|
| 16 | }
|
|---|
| 17 | }
|
|---|
| 18 | return accumulator;
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | exports.reduce = reduce;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.