Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js fibonacci sequence

var i;
    var fib = []; // Initialize array!

    fib[0] = 0;
    fib[1] = 1;
    for (i = 2; i <= 10; i++) {
      // Next fibonacci number = previous + one before previous
      // Translated to JavaScript:
      fib[i] = fib[i - 2] + fib[i - 1];
      console.log(fib[i]);
    }
Source by ide.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #js #fibonacci #sequence
ADD COMMENT
Topic
Name
3+1 =