Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var IS_PURE = require('../internals/is-pure');
|
---|
4 | var anObject = require('../internals/an-object');
|
---|
5 | var aFunction = require('../internals/a-function');
|
---|
6 | var getSetIterator = require('../internals/get-set-iterator');
|
---|
7 | var iterate = require('../internals/iterate');
|
---|
8 |
|
---|
9 | // `Set.prototype.reduce` method
|
---|
10 | // https://github.com/tc39/proposal-collection-methods
|
---|
11 | $({ target: 'Set', proto: true, real: true, forced: IS_PURE }, {
|
---|
12 | reduce: function reduce(callbackfn /* , initialValue */) {
|
---|
13 | var set = anObject(this);
|
---|
14 | var iterator = getSetIterator(set);
|
---|
15 | var noInitial = arguments.length < 2;
|
---|
16 | var accumulator = noInitial ? undefined : arguments[1];
|
---|
17 | aFunction(callbackfn);
|
---|
18 | iterate(iterator, function (value) {
|
---|
19 | if (noInitial) {
|
---|
20 | noInitial = false;
|
---|
21 | accumulator = value;
|
---|
22 | } else {
|
---|
23 | accumulator = callbackfn(accumulator, value, value, set);
|
---|
24 | }
|
---|
25 | }, { IS_ITERATOR: true });
|
---|
26 | if (noInitial) throw TypeError('Reduce of empty set with no initial value');
|
---|
27 | return accumulator;
|
---|
28 | }
|
---|
29 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.