source: node_modules/es-toolkit/dist/map/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: 567 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5function reduce(map, callback, initialValue) {
6 if (initialValue == null && map.size === 0) {
7 throw new TypeError('Reduce of empty map with no initial value');
8 }
9 let accumulator = initialValue;
10 for (const [key, value] of map) {
11 if (accumulator == null) {
12 accumulator = value;
13 }
14 else {
15 accumulator = callback(accumulator, value, key, map);
16 }
17 }
18 return accumulator;
19}
20
21exports.reduce = reduce;
Note: See TracBrowser for help on using the repository browser.