main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
925 bytes
|
Rev | Line | |
---|
[79a0317] | 1 | 'use strict';
|
---|
| 2 | var $ = require('../internals/export');
|
---|
| 3 | var aCallable = require('../internals/a-callable');
|
---|
| 4 | var aSet = require('../internals/a-set');
|
---|
| 5 | var iterate = require('../internals/set-iterate');
|
---|
| 6 |
|
---|
| 7 | var $TypeError = TypeError;
|
---|
| 8 |
|
---|
| 9 | // `Set.prototype.reduce` method
|
---|
| 10 | // https://github.com/tc39/proposal-collection-methods
|
---|
| 11 | $({ target: 'Set', proto: true, real: true, forced: true }, {
|
---|
| 12 | reduce: function reduce(callbackfn /* , initialValue */) {
|
---|
| 13 | var set = aSet(this);
|
---|
| 14 | var noInitial = arguments.length < 2;
|
---|
| 15 | var accumulator = noInitial ? undefined : arguments[1];
|
---|
| 16 | aCallable(callbackfn);
|
---|
| 17 | iterate(set, function (value) {
|
---|
| 18 | if (noInitial) {
|
---|
| 19 | noInitial = false;
|
---|
| 20 | accumulator = value;
|
---|
| 21 | } else {
|
---|
| 22 | accumulator = callbackfn(accumulator, value, value, set);
|
---|
| 23 | }
|
---|
| 24 | });
|
---|
| 25 | if (noInitial) throw new $TypeError('Reduce of empty set with no initial value');
|
---|
| 26 | return accumulator;
|
---|
| 27 | }
|
---|
| 28 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.