6 function reduce(arr, fn, initVal) {
7 // check for args.length since initVal might be "undefined" see #gh-57
8 var hasInit = arguments.length > 2,
11 if (arr == null || !arr.length) {
13 throw new Error('reduce of empty array with no initial value');
19 var i = -1, len = arr.length;
25 result = fn(result, arr[i], i, arr);