Although I have not come across any questions that address my specific issue, it may be a duplicate.
Imagine having an array similar to this:
var hundred = [1,2,3,4,5...100]
This particular array consists of 100 elements, ranging from 1 to 100.
Given an integer value, how can I divide this array into another array with the same number of elements, but distributed evenly in the following manner?
var integer = 2;
var hundred = [50,50,50,50,50,50...100,100,100,100,100,100]
In this scenario, there are 50 elements with a value of 50 and 50 elements with a value of 100 due to the integer being 2.
I struggle with mathematics, so please forgive any inaccuracies. However, I trust you comprehend what I'm trying to convey. The resulting array must retain the same number of indices post-calculation.
Edit (Since formulating clear questions is not my forte, I will provide the code where I require assistance):
I currently possess a frequencybin array (from the AudioContext analyser):
var fbc_array = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(fbc_array);
This specific array contains a defined number of elements (representing audio frequencies).
Furthermore, I have a spectrum analyzer with a predetermined number of "bars." For instance, if there are only 3 bars, how could I split the fbc_array such that each bar houses an evenly distributed frequency range? For example, with 3 bars, one would contain bass, another the mids, and the last the treble.
To iterate over each bar, I implement a for loop:
for (i = 0; i < bars; i++) {
bar_x = i * canspace;
bar_width = 2;
bar_height = -3 - (fbc_array[i] / 2);
ctx.fillRect(bar_x, canvas.height, bar_width, bar_height);
}