Created
July 4, 2021 15:55
-
-
Save kharioki/ef7c9c398348efaf9a3cebab9c5c9791 to your computer and use it in GitHub Desktop.
Tribonacci - it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next.
This file contains hidden or 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(n) { | |
| let seq = [1,1,1]; | |
| let index; | |
| for (let i = 3; i < n; i++) { | |
| seq.push(seq[seq.length - 1] + seq[seq.length - 2] + seq[seq.length - 3]) | |
| } | |
| console.log(seq) | |
| return seq.slice(0, n); | |
| } | |
| tribonacci(12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment