SHARE
TWEET

Untitled

a guest Oct 16th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lastKNumbersSequance (n, k) {
  2.     let result = [1]
  3.     for (let i = 1; i < n; i++) {
  4.        let index = Math.max(i - k, 0);
  5.  
  6.        let subArr = result.slice(index);
  7.        let sum = 0;
  8.        for (const num of subArr) {
  9.            sum += num
  10.        }
  11.     result.push(sum);        
  12.     }
  13.     console.log(result.join(' '));
  14. }
  15.  
  16. lastKNumbersSequance(6, 3)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top