Array Reduce Transformation - Manually & BuiltIn fns
Intuition\nMy Intution in this question is so Simple, to use directly reducer function, but it is illegal in this, so i construct the Idea to make the same resu
# Intuition\nMy Intution in this question is so Simple, to use directly reducer function, but it is illegal in this, so i construct the Idea to make the same result as possible with not using as direct resulting function by manual method to solve it.\n\n# Approach\n***Approach for Code 1:*** This implementation uses the built-in Array.prototype.reduce function to directly compute the result by applying the provided fn iteratively over nums, starting with the init value.\n\n***Approach for Code 2:*** This manual implementation initializes the result with init and iterates through nums using a for loop, applying fn at each step to update the result.\n\n# Complexity\n- Time complexity: **O(n)**\n\n- Space complexity: **O(1)**\n\n# Illegal Try - Use Direct built-in fn:\n### Code\n```javascript []\nvar reduce = function(nums, fn, init) {\n    return nums.reduce(fn,init);\n};\n```\n\n# Best Method:\n### Code\n```javascript []\nvar reduce = function(nums, fn, init) {\n    let result = init;\n    if(nums.length == 0) return result;\n    for(let i=0; i<nums.length; i++){\n        result = fn(result, nums[i]);\n    }\n    return result;\n};\n```
['JavaScript']