g2601_2700.s2626_array_reduce_transformation.solution.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
The newest version!
// #Easy #2023_08_31_Time_52_ms_(91.40%)_Space_44.2_MB_(82.03%)
type Fn = (accum: number, curr: number) => number
function reduce(nums: number[], fn: Fn, init: number): number {
let accumulator = init
nums.forEach((num) => {
accumulator = fn(accumulator, num)
})
return accumulator
}
export { reduce }
© 2015 - 2024 Weber Informatics LLC | Privacy Policy