source: node_modules/es-toolkit/dist/map/reduce.mjs

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

Added visualizations

  • Property mode set to 100644
File size: 472 bytes
Line 
1function reduce(map, callback, initialValue) {
2 if (initialValue == null && map.size === 0) {
3 throw new TypeError('Reduce of empty map with no initial value');
4 }
5 let accumulator = initialValue;
6 for (const [key, value] of map) {
7 if (accumulator == null) {
8 accumulator = value;
9 }
10 else {
11 accumulator = callback(accumulator, value, key, map);
12 }
13 }
14 return accumulator;
15}
16
17export { reduce };
Note: See TracBrowser for help on using the repository browser.