function fibonacci(numberOfItems){ let num1 = 0, num2 = 1, fibArr=[]; fibArr.push(num1); fibArr.push(num2); for(let i=0; i<numberOfItems -2; i++){ let sum = num1 + num2; fibArr.push(sum); num1 = num2; num2 = sum; } return fibArr; } console.log(fibonacci(8));
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter