AreWe

01. Number Pyramid

Feb 22nd, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.     let n = Number(input.shift());
  3.     let times=1, counter = 2, output = '1\n';
  4.    
  5.     while(counter <= n) {
  6.         let end = counter+times;
  7.         for(let i=counter; i <= (end < n ? end : n); i++) {
  8.             output += i + ' ';
  9.         }
  10.         output+='\n';
  11.         counter+=1+times++;
  12.     }
  13.  
  14.     console.log(output);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment