Advertisement
PowerCell46

NxN Matrix JS

Nov 21st, 2022
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function matrix(num) {
  2.  
  3.     let array = []; // we create a new empty array;
  4.     for(let index = 0; index < num; index++) {
  5.         array.push(num); // we create a For cycle which pushes the inputed number on every rotation to the empty array;
  6.     }
  7.     array = array.join(" "); // we convert the array to a string;
  8.  
  9.     for(let currentColumn = 1; currentColumn <= num; currentColumn++) {
  10.     console.log(array); // on every column we print the array;
  11.     }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement