Discover how a higher order function has a return type. Often the return type of a higher order function is a collection. That means that the collection being returned can have higher order functions called on them. This is called chaining methods or method chaining. A call to map returns a collection that could then be sorted, for example.
- [Instructor] So another great optimization…or powerful use of higher order functions is chaining.…Higher order functions return something, right?…Most of them do.…Obviously sort doesn't, but many, many of them do.…And they often return things like collections,…things that you were calling them on to begin with.…So you could chain functions together…and call other higher-order functions on what was returned.…So let's look at doing that.…So once again I'm going to delete all my code other than…my array of names and I'm going to look for the first name…that has the letter E when they've been sorted.…
So I'm going to need two higher order functions for that.…So I'll say let first E equal names dot sort…I'm going to called sorted because I want them returned.…And then I'm going to say first, where.…V1 I'll say.…And I'll return v1 contains E,…and again I'll call lower-cased on v1.…Now we know from our optimizations we can do better…than this but let's go with this for now.…
Let's see if this works.…So I'll print first E and it should sort them…
- What are closures?
- Closures and function types
- Basic higher-order functions, including sort and forEach
- Powerful higher-order functions, including map and reduce
- Passing functions
- Closure optimizations
- Higher-order functions on sets, dictionaries, and strings