web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.1 KiB

  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. // `Set.prototype.reduce` method
  9. // https://github.com/tc39/proposal-collection-methods
  10. $({ target: 'Set', proto: true, real: true, forced: IS_PURE }, {
  11. reduce: function reduce(callbackfn /* , initialValue */) {
  12. var set = anObject(this);
  13. var iterator = getSetIterator(set);
  14. var noInitial = arguments.length < 2;
  15. var accumulator = noInitial ? undefined : arguments[1];
  16. aFunction(callbackfn);
  17. iterate(iterator, function (value) {
  18. if (noInitial) {
  19. noInitial = false;
  20. accumulator = value;
  21. } else {
  22. accumulator = callbackfn(accumulator, value, value, set);
  23. }
  24. }, { IS_ITERATOR: true });
  25. if (noInitial) throw TypeError('Reduce of empty set with no initial value');
  26. return accumulator;
  27. }
  28. });