I have a object like so (replaced with dummy data for simplicity, in the real case each of the integer elements is an object):
const dummyObject = {
A: [
[ 1, 2 ],
[ 3, 4 ],
[ 5, 6 ]
],
B: [
[ 7 ],
[ 8 ]
],
C: [
[ 9, 10, 11 ],
[ 12, 13, 14 ],
[ 15, 16, 17 ]
]
}
Note that all integer arrays (inner arrays) in each property A
, B
or C
are of equal length, and the length of outer arrays (containing integer arrays) can vary. There can also be varying amount of properties (D
, E
, ...)
Now I want to loop over the arrays in a specific fashion, where each iteration forms a result array:
//
// Result arrays (18 total):
//
// 1st iteration
[ 1, 2, 7, 9, 10, 11 ]
// 2nd iteration
[ 1, 2, 7, 12, 13, 14 ]
// 3rd
[ 1, 2, 7, 15, 16, 17 ]
// 4th
[ 1, 2, 8, 9, 10, 11 ]
// 5th
[ 1, 2, 8, 12, 13, 14 ]
// ...
// 18th and final iteration
[ 5, 6, 8, 15, 16, 17 ]
I could manage to do this loop, but each time I append a integer array to a result array, I want to validate the result array. If the validation fails I want to discard the result array and start the next iteration. Example:
//
// Same loop, but validate result array after every update.
//
// 1st iteration: Result array fails validation after the "[ 7 ]" array is added to it,
// discard this result array and start the 2nd iteration immediately.
[ 1, 2, 7 ]
// 2nd iteration
// ...