Created
June 20, 2010 15:45
-
-
Save naush/445915 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fib_recursive(n) { | |
| if (n <= 1) | |
| return n; | |
| return fib_recursive(n - 1) + fib_recursive(n - 2); | |
| } | |
| var fib = new Object(); | |
| fib.recursive = function(n) { | |
| if (n <= 1) | |
| return n; | |
| return this.recursive(n - 1) + this.recursive(n - 2); | |
| } | |
| fib.iterative = function(n) { | |
| var a = 0; | |
| var b = 1; | |
| var c = 0; | |
| for (i = 0; i < n; i++) { | |
| c = a + b; | |
| a = b; | |
| b = c; | |
| } | |
| return a; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment