Untitled

Oct 17th, 2021
731
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. // table size
2. let colCount = 15;
3. let rowCount = 15;
4.
5. let maxNumber = colCount * rowCount - 1; // last number in the table
6.
7. // compute maximal amount of digits
8. let x = maxNumber;
9. let digits = 0;
10. if (x == 0){
11.     digits = 1;
12. } else {
13.     while(x > 0){
14.         x = x - x % 10;
15.         x = x / 10;
16.         digits = digits + 1;
17.     }
18. }
19. let maxDigits = digits;
20.
21. // print table itself
22. let colNo = 0;
23. let row = "";
24. let rowNo = 0;
25. while(rowNo < rowCount){ // for every row
26.     colNo = 0;
27.     row = "";
28.     while(colNo < colCount){ // for every column
29.         let currentNumber = (rowNo * colCount + colNo);
30.
31.         // compute how many digits does currentNumber have
32.         let x = currentNumber;
33.         let digits = 0;
34.         if (x == 0){
35.             digits = 1;
36.         } else {
37.             while(x > 0){
38.                 x = x - x % 10;
39.                 x = x / 10;
40.                 digits = digits + 1;
41.             }
42.         }
43.         let currentDigits = digits;
44.
45.         // print spaces for every missing digit
46.         while(currentDigits < maxDigits){
47.             row += "0";
48.             currentDigits = currentDigits + 1;
49.         }
50.
51.         // maintain loop
52.         row += currentNumber + " ";
53.         colNo = colNo + 1;
54.     }
55.     // maintain loop
56.     rowNo = rowNo + 1;
57.     console.log(row);
58. }
59.
RAW Paste Data