code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

01 Fibonocci

/**
 * 
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

// Return the nth fibonocci number
// fib(1) == 1
// fib(2) == 1
// fib(n) = fib(n-1) + fib(n-2) 

function fibonocci(value) {
  if(value == 1 || value == 2){
    return 1
  }
  return fibonocci(value - 1) + fibonocci(value - 2)
}

test('fibonocci', () => {
  expect(fibonocci(6)).toEqual(8)
});

Created 2019-12-02T02:42:51+05:30 · Edit