Implementing Custom Array Reduction Without Using Built-in Methods 🛠️➡️📉
Problem UnderstandingIn this problem, we are tasked with reducing an array of integers, nums, using a provided reducer function, fn, and an initial value, init.
# Problem Understanding
In this problem, we are tasked with reducing an array of integers, nums, using a provided reducer function, fn, and an initial value, init. The goal is to sequentially apply fn to accumulate a single result, starting with init and processing each element in nums. Notably, we must achieve this without utilizing the built-in Array.prototype.reduce method.

# Approach
1. ## Initialize the Accumulator: 
Begin by setting a variable, total, to the initial value, init. This variable will hold the cumulative result as we iterate through the array.

2. ## Iterate Through the Array: 
Use a for loop to traverse each element in nums. For each element, update total by applying the reducer function fn to the current total and the current array element.

3. ## Return the Final Result: 
After processing all elements, total contains the reduced value, which we then return.

This method ensures that we manually perform the reduction operation without relying on the built-in reduce method, thereby meeting the problem's constraints.

# Complexity
- Time complexity:
 O(n)

- Space complexity:
O(1)

# Example Usage:
Suppose we have an array nums = [1️⃣, 2️⃣, 3️⃣, 4️⃣], a reducer function fn = (a, b) => a + b, and an initial value init = 0️⃣. Using our reduce function:
```
const result = reduce(nums, fn, init);
console.log(result); // Output: 🔟
```
Here, the function computes the sum of all elements in the array, starting from the initial value 0️⃣.

This approach provides a clear and efficient way to perform array reduction without using the built-in reduce method, adhering to the problem's requirements.


# Code
```javascript []
/**
 * @param {number[]} nums
 * @param {Function} fn
 * @param {number} init
 * @return {number}
 */
var reduce = function(nums, fn, init) {
    let total = init
    for(let i = 0; i < nums.length; i++){
        total = fn(total, nums[i])
    }
    return total
};
```
['JavaScript']