Created
February 1, 2016 17:13
-
-
Save giannispan/bdaab6e5470f48d77322 to your computer and use it in GitHub Desktop.
Tribonacci 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
function tribonacci(signature,n){ | |
console.log(signature); | |
console.log(n); | |
var i; | |
var fib = new Array(); | |
if (n == 0) return fib; | |
if (n > 3) { | |
fib[0] = signature[0]; | |
fib[1] = signature[1]; | |
fib[2] = signature[2]; | |
for (i = 3; i < n; i++) | |
fib[i] = fib[i-3] + fib[i-2] + fib[i-1]; | |
return fib; | |
} | |
else if (n <= 3) { | |
for (i = 0; i < n; i++) | |
fib[i] = signature[i]; | |
return fib; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment