aboutsummaryrefslogtreecommitdiff
path: root/entries/kevindhir/ts/fib.ts
blob: f126a8b3784ff7b8b2cb59d72e071d8c203a73e3 (plain) (blame)
1
2
3
4
5
6
7
8
let memo = {1: 1};

function fib(n: number): number {
    if(n <= 0) return 0;
    if(memo[n]) return memo[n];
    memo[n] = fib(n-1) + fib(n-2);
    return memo[n];
};