Hello Tsoding,
the operation of printing full rows and the last reminder row can both happen in a single impl.
the inner loop checks for both ROW count and also preserve overall SIZE limit.
here is a runnable example in JS:
var data = [...new Array(100)].map((_,i)=>i+101);
var row_size = 7;
for(let i=0; i<data.length; ) {
var out = " ";
for (let w=0; w<row_size && i<data.length; ++w, ++i) {
out += data[i].toString() + ", ";
}
console.log(out);
}
outer loop counter should move only when we print each item, so I had to move it inside the second loop.
Hello Tsoding, the operation of printing full rows and the last reminder row can both happen in a single impl. the inner loop checks for both ROW count and also preserve overall SIZE limit.
here is a runnable example in JS:
outer loop counter should move only when we print each item, so I had to move it inside the second loop.