The Array.filter() method is used to create list exclusions. Each item in the list is passed to a function which returns a Boolean value representing whether that item should be included in the list or not. A new list of these filtered items is returned, leaving the original list unmodified.
(funky music)…- Let's talk about exclusion.…I take a list and there are certain…items that I want to keep in the list…and certain items that I want to exclude from the list.…I want to filter those items out.…You might end up with a list…that has a whole bunch of numbers in it,…and then in certain places because…of whatever you were using to…create that list of numbers,…you might have some null values…or some undefined values,…and you want to filter those things out…'cause you only want to produce…your operations across a list of real numbers.…
So you have some things that you want to filter out.…You might want to filter out…anything that's not an odd number.…You might want to filter out the evens…by saying my predicate is odd.…So here, line one, my isOdd function…takes advantage of the mathematical modulus.…Modulus two is going to return one…for an odd number, zero for an even number.…So, what I'm saying here is if…the number returns one, then my…expression there on line one, on line one there,…that expression returns true.…
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.