Javascript examples for Array:reduce
Using Optional parameter in array reduce function
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/* w w w .j a v a 2 s .co m*/ function reduce(arr, func, start) { if (arr.length == 0) { return start; } var accum = typeof start == 'undefined' ? arr[0] : func(start, arr[0]); return reduce(arr.slice(1), func, accum); } console.log(reduce([1,2,34,5,6,7,8,9], function(a,b){return a + b;})); } </script> </head> <body> </body> </html>