leetcode 30 days js challenge
Easy
2626. Array Reduce Transformation
Given an integer array nums
, a reducer function fn
, and an initial value init
, return a reduced array.
A reduced array is created by applying the following operation: val = fn(init, nums[0])
, val = fn(val, nums[1])
, val = fn(val, nums[2])
, ...
until every element in the array has been processed. The final value of val
is returned.
If the length of the array is 0, it should return init
.
Please solve it without using the built-in Array.reduce
method.
Example 1:
Example 2:
Example 3:
Constraints:
0 <= nums.length <= 1000
0 <= nums[i] <= 1000
0 <= init <= 1000
SheepWed, May 10, 2023