SHARE
TWEET

Untitled

a guest Oct 14th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top