DEV Community

Discussion on: You don't need Array.reduce()

Collapse
 
andrewzhurov profile image
Andrew Zhurov

Is this correct?

const pipeOnce = (fn1, fn2) => (args) => (fn2(fn1(args)));
const pipe = (...ops) => ops.reduce(pipeOnce);

It seems for me pipeOnce should be

(acc, fn) => fn(acc)

Though it would not be 'pipeOnce' by semantic anymore:)

Collapse
 
trusktr profile image
Joe Pea

Heh, well this shows that thinking about it is more complicated than the for..of loops.