Skip to content

Instantly share code, notes, and snippets.

@lambdaydoty
Created September 26, 2019 11:01
Show Gist options
  • Save lambdaydoty/ff0915bb28350cde2eca445143ab2946 to your computer and use it in GitHub Desktop.
Save lambdaydoty/ff0915bb28350cde2eca445143ab2946 to your computer and use it in GitHub Desktop.
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