Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement