Created
October 8, 2017 22:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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