Version 1
[yaffs-website] / node_modules / core-js / library / modules / _array-reduce.js
1 var aFunction = require('./_a-function')
2   , toObject  = require('./_to-object')
3   , IObject   = require('./_iobject')
4   , toLength  = require('./_to-length');
5
6 module.exports = function(that, callbackfn, aLen, memo, isRight){
7   aFunction(callbackfn);
8   var O      = toObject(that)
9     , self   = IObject(O)
10     , length = toLength(O.length)
11     , index  = isRight ? length - 1 : 0
12     , i      = isRight ? -1 : 1;
13   if(aLen < 2)for(;;){
14     if(index in self){
15       memo = self[index];
16       index += i;
17       break;
18     }
19     index += i;
20     if(isRight ? index < 0 : length <= index){
21       throw TypeError('Reduce of empty array with no initial value');
22     }
23   }
24   for(;isRight ? index >= 0 : length > index; index += i)if(index in self){
25     memo = callbackfn(memo, self[index], index, O);
26   }
27   return memo;
28 };