source: node_modules/es-toolkit/dist/set/reduce.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 562 bytes
RevLine 
[a762898]1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5function 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
21exports.reduce = reduce;
Note: See TracBrowser for help on using the repository browser.