ErolKZ

Untitled

Oct 13th, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. function solve (a, b) {
  2.  
  3.  
  4.  
  5. let arr2 = [1];
  6.  
  7. let iterator = 0;
  8.  
  9.  
  10.  
  11.  
  12. for (let i = 0; i < a - 1; i++) {
  13.  
  14. if (arr2.length <= b) {
  15.  
  16. iterator = 0;
  17.  
  18. } else {
  19.  
  20. iterator = arr2.length - b;
  21.  
  22. }
  23.  
  24. arr2.push(arr2.slice(iterator, b + iterator).reduce((acc, curr) => acc + curr));
  25.  
  26. }
  27.  
  28.  
  29.  
  30. console.log(arr2.join(' '));
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment