Advertisement
EntropyStarRover

Arrays Advanced - Lab.04. Last K Numbers

Jun 28th, 2019
156
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lastKseq(lengthOfSeq, previousElementCount) {
  2.     let arr = [1];
  3.     for (let i = 1; i < lengthOfSeq; i++) {
  4.         let nextElement = 0;
  5.  
  6.         for (let j = 1; j <= previousElementCount; j++) {
  7.             if (i - j >= 0) {
  8.                 nextElement += (arr[i - j]);
  9.             }
  10.         }    
  11.         arr.push(nextElement);
  12.     }
  13.     console.log(arr.join(" "));
  14. }
Advertisement
RAW Paste Data Copied
Advertisement