tsoding / musializer

Music Visualizer
MIT License
953 stars 100 forks source link

refactor bundle byte print in rows #85

Closed HKhademian closed 9 months ago

HKhademian commented 9 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);
}