1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
const main = () => { const p: Function = console.log; const fibonacci: Function = (n: number): number => { switch (n) { case 0: return 0; case 1: return 1; default: return fibonacci(n - 1) + fibonacci(n - 2); } }; const sub = () => { const f: Function = fibonacci; const max: number = 20; for (let i: number = 0; i <= max; i++) { p("f(" + i + ") = " + f(i)); } }; sub(); }; main(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
f(0) = 0 f(1) = 1 f(2) = 1 f(3) = 2 f(4) = 3 f(5) = 5 f(6) = 8 f(7) = 13 f(8) = 21 f(9) = 34 f(10) = 55 f(11) = 89 f(12) = 144 f(13) = 233 f(14) = 377 f(15) = 610 f(16) = 987 f(17) = 1597 f(18) = 2584 f(19) = 4181 f(20) = 6765 |