SOURCE


const flattenDeep = (arr) => {
    return arr.reduce((prev, next) => {
        return prev + next;
    }, 0);
};

console.log(flattenDeep([1, 2, 3, 4, 5]));


Array.prototype.myReduce = (fn, initVal) => {
    let result = initVal;
    let i = 0;

    if (typeof initVal === 'undefined') {
        result = this[i];
        i++
    };

    while(i<this.length) {
        result = fn(result, this[i])
    }

    return result;
}
console 命令行工具 X clear

                    
>
console