Created
September 26, 2019 11:01
-
-
Save lambdaydoty/ff0915bb28350cde2eca445143ab2946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda') | |
const { equals, T, cond, always, range } = R | |
/* dispatch by ramda */ | |
function yaff (n) { | |
return cond([ | |
[equals(0), always(1)], | |
[equals(1), always(1)], | |
[T, x => yaff(x - 1) + yaff(x - 2)], | |
])(n) | |
} | |
/* dispatch by conditional */ | |
function fn (x) { | |
return x === 0 ? 1 | |
: (x === 1) ? 1 | |
: fn(x - 1) + fn(x - 2) | |
} | |
/* dispatch by logical: cannot handle `falsy` return! */ | |
function gn (x) { | |
return ((x === 0) && 1) || | |
((x === 1) && 1) || | |
(gn(x - 1) + gn(x - 2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment