I’ve been stuck on this challenge since yesterday. I’ve red articles/documentations and YouTube videos to have some insights on what’s going on. I did understand the callback functions and some HOF slightly but still a little bit lost. I finished the first and the second step of the exercise and on the way to finish up the last step.
I just need someone who got pass through this exercise and help me to break all the parts and explain it to me so I can fully understand of why is this in here and and there.
A higher-order function is a function that either accepts functions as parameters, returns a function, or both!
I’ll give a simple example of a function accepting another function as a parameter:
/* 1. regular function, in this context it's a callback function
because we are passing it to another function */
function stateHunger() {
return `I'm hungry!`;
}
/* 2. this is also a normal function, and it's about to
take the #1 as a parameter, making it high-order technically
by CC's definition. MDN differs slightly but I don't know if it's
just superficial nuance */
function communicate(thought) {
console.log(thought);
}
// invocation of #2 with #1 as its parameter
communicate( stateHunger() );
//output: "I'm hungry!"