Write a function named flow
that receives one or more parameters
The function should return a new function - let's call it run
- that will receive one or more parameters. It will successively invoke the pure functions, in order, passing the result of the previous invocation as the argument to the next one.
The run
function will return the result of the last pure function invocation.
The first pure function should receive as parameters all the parameters received by
run
.
const add = (a, b) => a + b;
const square = (a) => a ** 2;
const run = flow(add, square, square);
console.log(run(1, 2)); // 81
/**
* We first invoke the `add` with (1, 2) as parameters,
* which returns 3.
*
* We then take this result and pass it to the `square`
* function, which returns 9.
*
* Finally, we pass this result to the `square` function
* again, and get 81.
*/