题解 | Array.reduce

Array.reduce

https://www.nowcoder.com/practice/213d0ef21cb841de8cf69fcc5ea60eb6

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <style>
       /* 填写样式 */
    </style>
</head>

<body>
    <!-- 填写标签 -->
    <script type="text/javascript">
        // 填写JavaScript
        Array.prototype._reduce = function(Fn,initialValue){
            if (typeof Fn !== 'function'){
                return;
            }
            const array = this;
            let result = initialValue ? initialValue : 0;
            for (let i = 0;i < array.length;i++){
                result = Fn.call(undefined,result,array[i],i,array);
            }
            return result;
        }
    </script>
</body>

</html>

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务