Higher order function

I need good source to learn higher order function J.s beside FreeCodeCamp because i dont know why i have problem with it and i checked many videos and i still having problems

1 Like

What part of the higher-order function section are you having a hard time with? There are really two things that distinguish a higher-order function - they either take a function as a parameter (like Array.map(), for example), or they return a function. Sounds simple, but it is a little mind twisting, at first.

A great source on that is found in chapter 5 of Eloquent Javascript. There, the reason behind them is explained, as well as the advantages they can provide. Further, going from a “traditional” function to a higher-order function is worked through. Very solid read.

1 Like

thx bro i have problems with sort and Recursion and promises

1 Like

Great! Solid point to start from. Personally, that’s exactly the order I would look at them.

First, getting comfortable with functions like .sort(). Most of the higher-order array functions are funky but fairly understandable (the ones like Array.map(), Array.filter(), Array.sort(), Array.some(), Array.all()). Array.reduce() is also understandable, but is more of a “swiss-army knife” of functions - you can use it to do all of the others. So getting comfortable with the idea of “there’s this method that runs on arrays, and takes in a function, and then does something to each member of that array…” is the place to start. Are you comfortable with Array.filter()?

Second, recursion. This is a little twisted, as you’re having a function that, in essence, returns itself. The concept behind recursion is a little more off-beat, but it is understandable, if you break it down. Here’s a blog post I wrote on recursion, it might help. It’s a challenging subject, a little more in-depth than higher-order functions, but still pretty understandable *(with time and practice).

Third, Promises (and also async/await, as they’re much the same thing). Basic promises take some getting used to, as we’re used to poking in a value, getting a result, and moving on to the next step. Promises require that we consider “what if I haven’t gotten that data…yet?” We need to code for “when that data gets here, do something”. This is another example of a higher-order function, as the .then() of a Promise takes in a function to run against whatever result the promise returned.

I strongly suggest you work through them in the exact order you mentioned them. The first and the third are both very well covered in that Eloquent Javascript book I’d linked above. I’ll look into resources dealing with recursion, and get back to you. In the meantime, as you go forward and have specific questions, know we’re here to support you.


Thank you alot :heart: i downloaded the book and i will read it thx alot agin :heart:

Here’s a good video resource from MPJ if you like: https://www.youtube.com/watch?v=BMUiFMZr7vk. I highly recommend his videos because he explains topics clearly and his videos are kind of lively.