Advertisement
ilianrusev

lastKnumbers

Jan 12th, 2022
732
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function numbers(n, k) {
  2.     let arr = [1];
  3.  
  4.     for (let i = 1; i < n; i++) {
  5.         let sumOfThree = 0;
  6.         for (let j = 1; j <= k; j++) {
  7.             let num = arr[i - j]
  8.             if (num !== undefined) {
  9.                 sumOfThree += num;
  10.             }
  11.         }
  12.         arr.push(sumOfThree);
  13.     }
  14.  
  15.     return arr;
  16. }
Advertisement
RAW Paste Data Copied
Advertisement