题解 | 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>