✌ Simple O(N) Solution ✌
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\nJavaScript []\nvar reduce = function(nums, fn, init) {\n    for(let i in nums) init
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n``` JavaScript []\nvar reduce = function(nums, fn, init) {\n    for(let i in nums) init = fn(init, nums[i]);\n    return init;\n};\n```
['JavaScript']