Higher-order functions

// 1. Takes one or many functions as arguments
function twice(f, v) {
  return f(f(v));
}

function add3(v) {
  return v + 3;
}
const result = twice(add3, 1);
console.log("Result is ", result);


// 2. Returns a function
function addX(x) {
  return function (y) {
    return x + y;
  }
}

const add1 = addX(1);
const res = add1(5); // will return 6
console.log("Result is ", res);