Guest User

Untitled

a guest
Oct 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. const pipe = (...fns ) =>
  2. fns.reduce( ( f, g ) => (...args ) => g( f(...args ) ) )
  3.  
  4. const fx1 = ( x ) => ( before = 0 ) => before + x
  5. const fx2 = ( x ) => ( before = 0 ) => before + ( x * x )
  6. const fx3 = ( x ) => ( before = 0 ) => before + ( x * x * x )
  7.  
  8. // f(x) = x^3 + x^2 + x
  9. const result = ( x ) => pipe( fx3( x ), fx2( x ), fx1( x ) )()
  10.  
  11. console.log( result( 2 ) )
  12. // 14
Add Comment
Please, Sign In to add comment