This is a similar question as this one: Complete missing sequence in array with zeros in javascript
However, I can't seem to go around this problem. This is my array:
const array = [
[5, 'a', 2.3],
[6, 'a', 1.7],
[7, 'a', 5.4],
[8, 'a', 2.8],
[9, 'a', 8.5],
[10, 'a', 9.2],
[2, 'b', 1.6],
[5, 'b', 5.7],
[6, 'b', 8.9],
[7, 'b', 3.5],
[8, 'b', 6.1],
[9, 'b', 1.8],
[10, 'b', 7.4],
];
console.log(array);
First element: this is my reference value, it ranges from 1 to 10.
Second element: this is a category value.
Third element: this is a value that belongs to the second element, which happened at a timestamp that belongs to the first element.
My issue: I need to make sure that all the unique categories in the second element of the array (e.g., a and b) have the following sequence in the first element: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. If they do not have one of these numbers, then I need to create it, and then assign null to the third element.
Therefore, this is my expected output:
[
[1, 'a', null],
[2, 'a', null],
[3, 'a', null],
[4, 'a', null],
[5, 'a', 2.3],
[6, 'a', 1.7],
[7, 'a', 5.4],
[8, 'a', 2.8],
[9, 'a', 8.5],
[10, 'a', 9.2],
[1, 'b', null],
[2, 'b', 1.6],
[3, 'b', null],
[4, 'b', null],
[5, 'b', 5.7],
[6, 'b', 8.9],
[7, 'b', 3.5],
[8, 'b', 6.1],
[9, 'b', 1.8],
[10, 'b', 7.4],
];
Any ideas?