Devlog - 2025-11-21
π What I Did
- Problems on codewars.
π§ What I Learned
Reduce()
array.reduce((accumulator, currentValue) => {
// logic
}, initialValue)
accumulator- Holds the running total or result.currentValue- The current item in the array during the loop.initialValue- What the accumulator starts with.
const arr = [1, 2, 3];
const sum = arr.reduce((acc, curr) => {
return acc + curr;
}, 0);
console.log(sum); // 6
- Works for numbers, strings, objects, arrays β anything.
- Replaces many loops.
- Very flexible.
π₯ Whatβs Next
- Lab projects on FCC.
| β Previous | Next β |