Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

fibonacci series in javascript

// fibonacci series in javascript
const fibonacciSeries = (num) => {
    let arr = [];
    for(let i = 0; i <= num; i++) {
      if(i == 0 || i == 1){
        arr[i] = i;
      }else{
        arr[i] = arr[i - 1] + arr[i - 2];
      }
    }
    return arr;
}
console.log(fibonacciSeries(6)) //[ 0, 1,  1,  2,  3, 5, 8];
 
PREVIOUS NEXT
Tagged: #fibonacci #series #javascript
ADD COMMENT
Topic
Name
5+1 =