Hi Skay, thanks for the article.
There is an incorrect comment in your code:
//Higher order function - takes 'func' as an argument & returns a 'func' for execution
const higherOrderFunction = function(func, a, b) {
return func(a, b);
}
This function is not actually returning a function, but rather the result of the callback function, which is data.
A more concise example might be:
const sum = function(a, b) {
return a + b;
}
//Higher order function - takes 'func' as an argument & returns a 'func' for execution
const higherOrderFunction = (func) => (a, b) => {
return func(a, b);
}
const sumFor = higherOrderFunction(sum);
console.log(sumFor(2,3));
Here, higherOrderFunction takes func and returns a function, which then takes a,b and return data.
Cheers!