Description
Function composition is a common technique in functional programming where multiple functions are combined into a single pipeline.
Each function in the chain passes its output as input to the next one — making the logic more modular and readable.
In this challenge, you’ll implement a simple pipe function that takes multiple single-argument functions and executes them in sequence.
Your Task
Implement a function pipe(...functions) that:
- Takes any number of unary (single-argument) functions.
- Returns a new function that takes one input.
- When executed, passes the input through all the provided functions from left to right.
- Returns the final result after all functions are applied.
Example
Input
const val = { salary: 10000 };
const getSalary = (person) => person.salary;
const addBonus = (netSalary) => netSalary + 1000;
const deductTax = (grossSalary) => grossSalary - grossSalary * 0.3;
const result = pipe(getSalary, addBonus, deductTax)(val);
console.log(result);
Output
7700Explanation
- getSalary({ salary: 10000 }) → 10000
- addBonus(10000) → 11000
- deductTax(11000) → 7700
 Final output = 7700
Expected Behavior
- Executes functions in the given order
- Passes each output as input to the next
- Returns final value after all functions are applied
- Supports any number of functions
