Kyle walks through the solution to exercise 3.
- First off, the main goal of this is to be able to handle…an arbitrary number of arguments.…So I'm going to take those off, those named ones…and in their place I'm going to take advantage…of that ES6 spread.…In this case, it's called the rest operator.…I like to call it the gather operator, by the way.…But ...args.…That's my gather operator so I'm going to gather…everything together into the array args.…Now, all recursive functions,…the main defining characteristic is that they…have a base case.…
Some way to know that it's time to stop…so they don't run forever and they have a recursive call.…So let's deal with the base case.…If the length of args is less than or equal to two,…that means I have all that I need to make a multiplication…between two elements using the multiplication operator.…So I'm going to take args of zero and args of one,…multiply them together and return that result.…So I'm going to simply say "return args of zero…times args of one."…I was asked in chat over the work break…what about other of those trivial base cases like…
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.