code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

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:30:51+05:18 · Edit