Easy and short
\nvar reduce = function (nums, fn, init) {\n  let res = init;\n\n  for (const i of nums) {\n    res = fn(res, i);\n  }\n  \n  return res;\n};\n\n\nThanks:)
```\nvar reduce = function (nums, fn, init) {\n  let res = init;\n\n  for (const i of nums) {\n    res = fn(res, i);\n  }\n  \n  return res;\n};\n```\n\nThanks:)
[]