tsoding / musializer

Music Visualizer
MIT License
877 stars 92 forks source link

Bundler reminder #86

Closed HKhademian closed 6 months ago

HKhademian commented 6 months ago

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.

rexim commented 6 months ago

Nice! Thank you so much!