1
function foo (...args) { return args.reduce(function (previousValue, currentValue) { // console.log(previousValue, currentValue) return previousValue += currentValue; }) } console.log(foo(1, 32, 34, 5, 6))
2
function sum () { var result = 0; for(var i = 0, len = arguments.length; i < len; i++) { result += arguments[i] } return result; } console.log(sum(1, 2, 3 , 4, 5))