I have two arrays:
category.data.xAxis // containing: ["0006", "0007", "0009", "0011", "0301"]category.data.yAxis // containing: [6.31412, 42.4245, 533.2234, 2345.5413, 3215.24]
How do I take a max length, say DATAPOINT_LENGTH_STANDARD = 540 and fill in every missing number-based string on the xAxis array? so that:
- The resulting xAxis array will read from "0000" to "0540" (or whatever the standard length is)
- The associated yAxis indexes will remain connected to the original xAxis datapoints (i.e. "0006" to 6.31412)
- Every newly created xAxis datapoint has an associated yAxis value of 0 (so the newly created "0000" xAxis entry will contain 0 in the yAxis at index 0 for both)
The xAxis value strings can be assumed to already be sorted from lowest to highest.
EDIT
The clarity of my question was an effort to help the community with finding a more straight-forward answer, but I suppose the exactness gave the appearance of a homework question. In response to the comments, my original attempt, which does not properly manipulate the x-axis and maintain proper 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);