Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. const R = require('ramda')
  2. const { equals, T, cond, always, range } = R
  3.  
  4. /* dispatch by ramda */
  5. function yaff (n) {
  6. return cond([
  7. [equals(0), always(1)],
  8. [equals(1), always(1)],
  9. [T, x => yaff(x - 1) + yaff(x - 2)],
  10. ])(n)
  11. }
  12.  
  13. /* dispatch by conditional */
  14. function fn (x) {
  15. return x === 0 ? 1
  16. : (x === 1) ? 1
  17. : fn(x - 1) + fn(x - 2)
  18. }
  19.  
  20. /* dispatch by logical: cannot handle `falsy` return! */
  21. function gn (x) {
  22. return ((x === 0) && 1) ||
  23. ((x === 1) && 1) ||
  24. (gn(x - 1) + gn(x - 2))
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement