2 var $ = require('../internals/export');
3 var global = require('../internals/global');
4 var IS_PURE = require('../internals/is-pure');
5 var anObject = require('../internals/an-object');
6 var aCallable = require('../internals/a-callable');
7 var getMapIterator = require('../internals/get-map-iterator');
8 var iterate = require('../internals/iterate');
10 var TypeError = global.TypeError;
12 // `Map.prototype.reduce` method
13 // https://github.com/tc39/proposal-collection-methods
14 $({ target: 'Map', proto: true, real: true, forced: IS_PURE }, {
15 reduce: function reduce(callbackfn /* , initialValue */) {
16 var map = anObject(this);
17 var iterator = getMapIterator(map);
18 var noInitial = arguments.length < 2;
19 var accumulator = noInitial ? undefined : arguments[1];
20 aCallable(callbackfn);
21 iterate(iterator, function (key, value) {
26 accumulator = callbackfn(accumulator, value, key, map);
28 }, { AS_ENTRIES: true, IS_ITERATOR: true });
29 if (noInitial) throw TypeError('Reduce of empty map with no initial value');