function reduce(arr, callback, init) { let ret = init; for(let i = 0; i < arr.length; i++) { ret = callback(ret, arr[i], i) } return ret; } console.log(reduce([1, 2], (init, value, index) => { return init + value }, 7))