My fancy name is Higher Order Function!

My fancy name is Higher Order Function!

They label me from higher order, but I don't forget my roots, I am still a function that simply operates on other functions!

Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.

Eloquent JavaScript (https://eloquentjavascript.net/05_higher_order.html#h_xxCc98lOBK)

Show me something

function getMeAMultiplierFunction(multiplyBy) {
  return function multiply(multiplyWith) {
    return multiplyBy * multiplyWith;
  }
}

const multiplyBy2 =  getMeAMultiplierFunction(2);
const multiplyBy5 =  getMeAMultiplierFunction(5);
multiplyBy2(5); // 10
multiplyBy5(5); // 25

I want more!

// Higher Order Universe
function letMeCheckItForYou(value, checkerFunc) {
 // People call me to check if some value meets THEIR requirements
 // I reply them yes or no (true/ false)
 // They call me higher order
 const yesOrNo =  checkerFunc(value);
 return yesOrNo;
}

// People Universe
// I am Sam, I like numbers greater than 10
const greaterThan10 = (n) => n > 10; 
// HOF is my friend, lemme ask him
letMeCheckItForYou(11, greaterThan10) // true

// I am Bing, I'd like to see if someones likes me
const doYouLikeMe = (val) => val === 'I like you';
//   HOF is my friend as well! I will ask him
letMeCheckItForYou('I like you', doYouLikeMe) // true

Read more about them on Eloquent JavaScript!