Better understanding higher order functions - helpful resources

Higher order functions was difficult for me too this video helped.

I breezed through most of the JS tutorial, but that section scared me. It felt as if the tutor was speaking too fast. I sat down this morning to have a go at it and I solved it on the first try.
If they can split that exercise into different steps, it would be much easier to follow.
It’s also annoying that I had to use other resources aka. FreeCodeCamp to understand what was being taught.

Personally, I like symbols, and despise long descriptive variable names at the processing level. Had this lesson been less verbose it might have had a greater chance of dissemination. As it is, it even confuses me. But then…

i think a lot of the ocnfusion and referincing online examples is the assumptoin of usage of objects which they haven’t covered yet - however, this was one of the best articles I saw - https://blog.bitsrc.io/understanding-higher-order-functions-in-javascript-75461803bad

I’ve watched this video several times, and for me, I didn’t find it super helpful. I’m sure we all agree Brad Traversy’s awesome, but in this particular video he demonstrated a handful JavaScript methods on arrays. I wished he’d explained better why they take the parameters they do (but I know that’s all a matter of ''Look it up in MDN"). I also felt like he quickly rushed through the concise body arrow function expressions - nice to see, but I would have much rather had more in-depth explanation of the concepts. It was a good review of Codecademy material, but for me it didn’t help me understand HOFs better.

I’ve yet to find THE video that enables my brain to wrap my head around this concept fully, but this one definitely helped me. FYI, I played this one at 1.75x speed which somehow helped. Just a suggestion.

https://youtu.be/25VUf6pUwEU

There are basically two types of higher order functions: One that takes a function and then uses that function internally to arrive at a return value; for instance,

Array.forEach(callback)

where callback is a function that does something with each object in the array as forEach iterates that array.

Array.filter(callback)

where callback is a predicate function (returns a boolean) where only the array elements that satisfy the predicate will be added to the return array.

Array.map(callback)

where the callback is a function to compute a new value from each of those values in Array and return an array of the new values.

Array.reduce(callback)

where callback is a function that computes a value, such as a + b while progressively reducing the Array elements to a single return value.

The other type is one that returns a function composed of the arguments passed in and that can be invoked at a later time.

times = a = > x => a * x

f = times(5)

console.log(f(25))    //  125

Notice that a is now a constant in f and x is the parameter?

2 Likes

Think of maths…

f(x) = ax

We’ve defined f(x) as, f(x) = 5x.

This is very common functionality when we get into the stew of things. You’ll find a million uses for both forms of HOF as you progress. Definitely segue into deeper study if this is a hanging point. It will be time well spent, and I mean practice, not videos.

1 Like

To be honest the higher order functions directions and teaching in this section is horrid. @Codeacademy please review this module it can use a lot of work. I understand functions and will say your jumping from 0 to 60 on this one!!!

2 Likes

trust me, (whoever it concerns) you will learn more on higher order functions from this playlist.