From the course: Learning Functional Programming with JavaScript ES6+
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Reducing - JavaScript Tutorial
From the course: Learning Functional Programming with JavaScript ES6+
Reducing
- [Narrator] The final built-in array function that we're going to discuss is called reduce. The purpose of this function might not be quite as apparent as map, filtered or sort. But reduce is definitely just as useful as, if not more useful than the other array functions. What reduce allows us to do is take an array of data, and reduce it down to a single value. So for example, we could take an array of numbers and reduce it down to a sum or an average. Essentially, what reduce does is starts with an initial value, say zero, and for each element in the array, it modifies its initial value in some way until after we've processed all our elements. We end up with the result. In the case of finding the sum of an array of numbers for example, we add each element to the initial value over and over again until we find our final result. And if we were trying to find the product of an array of numbers, we'd multiply each element by the initial value, and so on. So what's the syntax of reduce?…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
JavaScript: Functional parts1m 53s
-
(Locked)
The spread operator5m 30s
-
Mapping5m 11s
-
(Locked)
Filtering6m 59s
-
(Locked)
Every/some5m 46s
-
(Locked)
Slicing3m 38s
-
(Locked)
Sorting5m 11s
-
(Locked)
Reducing6m 23s
-
(Locked)
Combining functions6m 40s
-
(Locked)
Challenge: Recreate the map function1m 3s
-
(Locked)
Solution: Recreate the map function3m 6s
-
(Locked)
-
-
-