tubeshowcase●1,194,391 videos♡ My collection 0
← Learn to Code

Learn to Code05:16

JavaScript reduce() method in 5 minutes! ♻️

Bro Code ↗

From the creator

// .reduce() = reduce the elements of an array // to a single value // ----------- EXAMPLE 1 ----------- const prices = [5, 30, 10, 25, 15, 20]; const total = prices.reduce(sum); console.log(`$${total.toFixed(2)}`); function sum(accumulator, element){ return accumulator + element; } // ----------- EXAMPLE 2 ----------- const scores = [75, 50, 90, 80, 65, 95]; const maximum = scores.reduce(getMax); const minimum = scores.reduce(getMin); console.log(maximum); console.log(minimum); function getMax(accumulator, element){ return Math.max(accumulator, element); } function getMin(accumulator, element){ return Math.min(accumulator, element); }

Published 2023-11-11 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code