One Line Solution 🚀🚀
Intuition\n\nThe intuition behind this code is to provide a wrapper function for the reduce() method of JavaScript arrays, allowing users to pass a custom funct
# Intuition\n\nThe intuition behind this code is to provide a wrapper function for the reduce() method of JavaScript arrays, allowing users to pass a custom function to perform a reduction operation on an array.\n\n# Approach\n\n1. The function reduce takes an array nums, a function fn, and an initial value init.\n2. It reduces the array nums using the reduce() method, which applies the provided function fn to each element of the array, accumulating the result starting with the initial value init.\n3. It returns the final accumulated value after the reduction operation.\n\n# Complexity\n**Time complexity**:\n- The time complexity of the reduce() method itself is O(n), where n is the length of the input array nums. This is because it needs to iterate through each element of the array to apply the provided function and perform the reduction operation.\n- The time complexity of applying the provided function fn depends on the complexity of the function itself. Let\'s denote it as O(f), where f is the complexity of fn.\n- Therefore, the overall time complexity is O(n * f), where n is the length of the input array and f is the complexity of the provided function.\n\n**Space complexity**:\n\n- The space complexity is O(1) because the function returns a single accumulated value, regardless of the size of the input array.\n- The space complexity does not depend on the size of the input array but rather on the space required to store the final accumulated value.\n- Thus, the space complexity is O(1).\n\n\n\n\n\n\n# 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    return nums.reduce(fn,init)\n    \n};\n```
['JavaScript']