Skip to content

Instantly share code, notes, and snippets.

@kianting
Created October 8, 2017 22:35
Show Gist options
  • Save kianting/db00bb589ab5dcfc40eadbcafe54a6a5 to your computer and use it in GitHub Desktop.
Save kianting/db00bb589ab5dcfc40eadbcafe54a6a5 to your computer and use it in GitHub Desktop.
A recursive function that generates a series of Fibonacci numbers based on 2 arguments, the first argument is the starting number of the Fibonacci sequence, the second number is total of elements to generate in the sequence.
// Write your code here.
var fibonaci = function(num, total)
{
if (total === 1){
return [num]
}else{
var list = fibonaci(num, total -1)
list.push(((list[list.length-2] != null) ? list[list.length-2] : 0) + list[list.length-1])
return list
}
};
console.log(fibonaci(5,3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment