Advertisement
Spocoman

01. Number Pyramid

Dec 30th, 2021 (edited)
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function numberPyramid(input) {
  2.     let num = Number(input[0]);
  3.     let counter = 1;
  4.  
  5.     for (let row = 1; row <= num && counter <= num; row++) {
  6.         let current = "";
  7.         for (let col = 1; col <= row && counter <= num; col++) {
  8.             current += counter + " ";
  9.             counter++;
  10.         }
  11.         console.log(current);
  12.     }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement