手写reduce()
function reduce(arr, callBack ,initVal){ if(!Array.isArray(arr) || !arr.length || typeof callBack != 'function') return []; let hasInitVal = initVal !== 'undefined'; let val = hasInitVal ? initVal : arr[0]; for(let i = 0, len = arr.length; i<len; i++){ val = callBack(value, arr[i], i, arr); } return val }