const ops = {
add: (a, b) => a + b,
subtract: (a, b) => a - b,
multiply: (a, b) => a * b,
divide: (a, b) => b !== 0 ? a / b : NaN,
};
const pipeline = (...fns) => (value) => fns.reduce((acc, fn) => fn(acc), value);
const double = (x) => ops.multiply(x, 2);
const addTen = (x) => ops.add(x, 10);
const halve = (x) => ops.divide(x, 2);
const subtractThree = (x) => ops.subtract(x, 3);
const transform = pipeline(double, addTen, halve, subtractThree);
const results = [5, 0, -4].map(transform);
console.log(results); Post #3192
2.31K
CHALLENGE
- ❤ 6
- 👍 2
- 🔥 1