Test case details

Preparation Code

function xbonacci_fast(signature, maxLength) { if (maxLength < signature.length) return signature.slice(0, maxLength); const length = signature.length; let initialSum = signature.reduce((acc, cur) => acc + cur, 0); const res = [...signature, initialSum]; initialSum -= res[0]; // remove first element to prepare for the loop for (let i = length; i < maxLength - 1; i++) { initialSum += res[res.length - 1]; res.push(initialSum); initialSum -= res[res.length - length - 1]; } return res; } function xbonacci_slow(signature, n){ const x = signature.length; const arr = [...signature]; for(let i = 0; i < n-x; i++) { arr.push(arr.slice(i, i+x).reduce((p,c)=>p+c)); } return arr.slice(0,n); }

Test cases

Test #1

xbonacci_fast([1,1,1,1,1], 1000);

Test #2

xbonacci_slow([1,1,1,1,1], 1000);