how do i combine a string and an int and find its value in an array?

Perhaps this code will help (I may be out by one on the index, but you can fix that)

var tribonacci = function(n) {
    let arr = [0, 1, 1];
    for (i = 2; i < n; i++) {
        arr.push(arr.slice(-3).reduce((a,b) => a+b));
    }
    return arr[n];
};
console.log(tribonacci(1))
console.log(tribonacci(2))
console.log(tribonacci(3))
console.log(tribonacci(4))
console.log(tribonacci(7))
console.log(tribonacci(14))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top