massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / array-reduce.js
1 var global = require('../internals/global');
2 var aCallable = require('../internals/a-callable');
3 var toObject = require('../internals/to-object');
4 var IndexedObject = require('../internals/indexed-object');
5 var lengthOfArrayLike = require('../internals/length-of-array-like');
6
7 var TypeError = global.TypeError;
8
9 // `Array.prototype.{ reduce, reduceRight }` methods implementation
10 var createMethod = function (IS_RIGHT) {
11   return function (that, callbackfn, argumentsLength, memo) {
12     aCallable(callbackfn);
13     var O = toObject(that);
14     var self = IndexedObject(O);
15     var length = lengthOfArrayLike(O);
16     var index = IS_RIGHT ? length - 1 : 0;
17     var i = IS_RIGHT ? -1 : 1;
18     if (argumentsLength < 2) while (true) {
19       if (index in self) {
20         memo = self[index];
21         index += i;
22         break;
23       }
24       index += i;
25       if (IS_RIGHT ? index < 0 : length <= index) {
26         throw TypeError('Reduce of empty array with no initial value');
27       }
28     }
29     for (;IS_RIGHT ? index >= 0 : length > index; index += i) if (index in self) {
30       memo = callbackfn(memo, self[index], index, O);
31     }
32     return memo;
33   };
34 };
35
36 module.exports = {
37   // `Array.prototype.reduce` method
38   // https://tc39.es/ecma262/#sec-array.prototype.reduce
39   left: createMethod(false),
40   // `Array.prototype.reduceRight` method
41   // https://tc39.es/ecma262/#sec-array.prototype.reduceright
42   right: createMethod(true)
43 };