Building off the previous solution, Kyle changes the addn() function to now work with an array of functions instead of an array of values. This allows him to incorporate the reduce() method.
(wood flute music)…Either iteratively or recursively,…this problem can be solved.…Finally, let's try to solve it with map and reduce.…Okay?…So, with map and reduce, what we can observe is that…the changing of a value to a function,…is a transformation, is it not?…So I can take arr, and simply call map…with foo as my function.…
That's going to make sure to wrap all…of my values into functions.…And now, I want to perform…a composition of all those functions.…Does everybody see that?…How do I do a composition?…- [Student] Reduce?…Right.…What does reduce take?…What's its first parameter, its first argument?…- [Student] An array?…It takes a predicate function.…Remember, because it's operating…on the array as a prototype method.…
So we don't have to pass the array in.…It's going to get that context already.…So, the first argument to .reduce is going to be…the predicate function, the function's going to do the work.…So, we'll define that function.…We know that function's going to get two arguments,…I'm just going to temporarily call them X and Y,…
This course was created by Frontend Masters. It was originally released on 03/08/2016. We're pleased to host this training in our library.
- Pure functions
- Manual composition
- Composition utility
- List operations
Skill Level Intermediate
1. Pure Functions
2. Composition and Immutability
3. Closure and Recursion
4. List Operations
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.