param { number } n return { number } function FibonacciRecursive ( n ) { if ( n < 2 ) { return n ; } else { return FibonacciRecursive ( n - 1 ) + FibonacciRecursive ( n - 2 ) ; } } param { number } n param { number [ ] } memory return { number } function FibonacciWithMemory ( n , memory ) { if ( ! memory ) { memory = [ ] ; } if ( n < 2 ) { return n ; } if ( ! memory [ n ] ) { memory [ n ] = FibonacciWithMemory ( n - 1 , memory ) + FibonacciWithMemory ( n - 2 , memory ) ; } return memory [ n ] ; } param { number } n return { number } function Fibonacci ( n ) { if ( n < 2 ) { return n ; } let i = 2 ; let pre = 1 ; let current = 1 ; let result = 0 ; while ( i ++ < n ) { result = pre + current ; pre = current ; current = result ; } return result ; } export { FibonacciRecursive , FibonacciWithMemory , Fibonacci } ;