# 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.

2 Likes