function lastKseq(lengthOfSeq, previousElementCount) { let arr = [1]; for (let i = 1; i < lengthOfSeq; i++) { let nextElement = 0; for (let j = 1; j <= previousElementCount; j++) { if (i - j >= 0) { nextElement += (arr[i - j]); } } arr.push(nextElement); } console.log(arr.join(" ")); }