Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const pipe = (...fns ) =>
- fns.reduce( ( f, g ) => (...args ) => g( f(...args ) ) )
- const fx1 = ( x ) => ( before = 0 ) => before + x
- const fx2 = ( x ) => ( before = 0 ) => before + ( x * x )
- const fx3 = ( x ) => ( before = 0 ) => before + ( x * x * x )
- // f(x) = x^3 + x^2 + x
- const result = ( x ) => pipe( fx3( x ), fx2( x ), fx1( x ) )()
- console.log( result( 2 ) )
- // 14
Add Comment
Please, Sign In to add comment