tribonacci

Solutions on MaxInterview for tribonacci by the best coders in the world

showing results for - "tribonacci"
Emely
25 Jun 2019
1const tribonacci = (signature,n) => {
2    let orgArr = [...signature]
3    let len = orgArr.length
4    let arr = []
5    if(n === 0){
6        return []
7    }else if(n < 3){
8        orgArr = orgArr.slice(0, n)
9    }else{
10        for(let i = len; i < n; i++){
11            if(i <= n){
12                arr = orgArr.slice(-3)
13                let nextValue = arr.reduce((acc, curr) => acc + curr, 0)
14                orgArr.push(nextValue)
15                arr = []
16            }else{
17                return 1
18            }
19        }
20    }
21    return orgArr
22}