I am working with two arrays:
xAxisData: ["0006", "0007", "0009", "0011", "0301"]
yAxisData: [6.31412, 42.4245, 533.2234, 2345.5413, 3215.24]
My goal is to standardize the length of the xAxis array to a maximum value, for example, DATAPOINT_LENGTH_STANDARD = 540
. This involves filling in any missing number-based strings in the xAxis array to achieve the following:
- The updated xAxis array should range from "0000" to "0540" (or any other standard length)
- The corresponding yAxis values should remain associated with their original xAxis data points (e.g. "0006" corresponds to 6.31412)
- Any newly added xAxis data points should have a yAxis value of 0 (e.g. the new entry "0000" will have a yAxis value of 0)
It is safe to assume that the xAxis value strings are already sorted from lowest to highest.
UPDATE:
In response to feedback, I attempted to clarify my question for the benefit of the community. However, it seems the level of detail may have made it appear like a homework assignment. Here is my original attempt, which did not fully manipulate the x-axis and maintain correct indexing:
let tempArray = categoryObject.data.xAxis;
let min = Math.min.apply(null, tempArray);
let max = Math.max.apply(null, tempArray);
while (min <= max) {
if (tempArray.indexOf(min.toString()) === -1) {
tempArray.push(min.toString());
categoryObject.data.yAxis.push(0);
}
min++;
}
console.log(tempArray);
console.log(categoryObject.data.yAxis);