Fixing the algorithm

This commit is contained in:
edumoreira1506 2019-08-27 12:03:55 -03:00
parent 9a9c92d353
commit d02bd00ed3

View File

@ -6,12 +6,14 @@
*/
export default function tribonacci(n) {
const tribSequence = [0];
let currentValue = 1;
let currentValue = 0;
if (n >= 2) {
tribSequence.push(currentValue);
}
currentValue += 1;
for (let i = 2; i < n; i += 1) {
tribSequence.push(currentValue);
currentValue += tribSequence[i - 1] + tribSequence[i - 2];