<JavaScript>
Code\n\n/**\n * @param {number[]} nums\n * @param {Function} fn\n * @param {number} init\n * @return {number}\n */\nvar reduce = function(nums, fn, init) {\n  l
# Code\n```\n/**\n * @param {number[]} nums\n * @param {Function} fn\n * @param {number} init\n * @return {number}\n */\nvar reduce = function(nums, fn, init) {\n  let val = init;\n  for (let i = 0; i < nums.length; i++) {\n    val = fn(val, nums[i]);\n  }\n  return val;\n};\n```
['JavaScript']