tsoding / musializer

Music Visualizer
MIT License
877 stars 92 forks source link

refactor bundle byte print in rows #85

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; ++i) {
    var out = "    ";
    for (let w=0; w<row_size  && i<data.length; ++w, ++i) {
        out += data[i].toString() + ", ";
    }
    console.log(out);
}