Advertisement
Czopski

Fibonnacci

Feb 9th, 2023
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fibonacciGenerator (n) {
  2. //Do NOT change any of the code above 👆
  3.    
  4.     //Write your code here:
  5.    
  6.    
  7. var output = [];
  8.  
  9. for(var i=0; i < n; i++){
  10.      
  11.     if (i === 0){
  12.         output[i] = 0;
  13.     }
  14.    
  15.     else if (i === 1){
  16.         output[i] = 1;
  17.     }
  18.    
  19.     else{
  20.     output[i] = Number(output[i-1]) + Number(output[i-2]);
  21.     }
  22.  
  23.  
  24. }
  25.  
  26. return output;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement