SOURCE

Array.prototype.myReduce = function (func, initialValue) {
    const arr = this
    const base = typeof initialValue === 'undefined' ? arr[0] : initialValue;
    const startIndex = typeof initialValue === 'undefined' ? 1 : 0;
    arr.slice(startIndex).forEach(function (val, index) {
        base = func(base, val, index + startIndex, arr)
    })
    return base
}
console 命令行工具 X clear

                    
>
console