[
[x1, y1, x2, y2],
[x1, y1, x2, y2],
[x1, y1, x2, y2]
]
const data = [
[1497052800, 100, 1597052800, 120, 1597052800, 120],
[1497139200, 140, 1597052800, 80],
[1497225600, 200, 1597052800, 222],
[1497312000, 80, 1597052800, 100],
]
[
[x1, y1],
[x1, y1],
[x1, y1]
]
[
[x2, y2],
[x2, y2],
[x2, y2]
]
const newArr = flattenDeep(data, 2)
.filter((e, i) => i % 2)
.reduce(
(acc, el, i) => [
...acc,
[flattenDeep(data, 2)[i * 2], flattenDeep(data, 2)[i * 2 + 1]]
],
[]
);
const data = [
[1497052800, 100, 1597052800, 120, 1597052800, 120],
[1497139200, 140, 1597052800, 80],
[1497225600, 200, 1597052800, 222],
[1497312000, 80, 1597052800, 100],
];
function getItems(arr, from, to) {
return arr.map(arr => arr.filter((e, id) => id >= from && id <= to));
}
// data - сам массив, 0,1 это диапазон индексов, с какого по какой делать выборку
getItems(data, 0, 1); // первые два
getItems(data, 2, 3); // вторые два
[x1,y1,z1,x2,y2,z2]
, то getItems(data, 0, 2);
getItems(data, 3, 5);
[x1,y1,x2,y2,x3,y3]
, то getItems(data, 0, 1);
getItems(data, 2, 3);
getItems(data, 4, 5);
const result = data.reduce((acc, curr) => {
curr.filter((_, i) => i % 2 === 0).forEach((item, i) => {
(acc[i] = acc[i] || []).push([item, curr[i * 2 + 1]]);
});
return acc;
}, Array(Math.max(...data.map((item) => item.length)) / 2).map(() => []));
console.log(result);
/*
[
[
[1497052800, 100],
[1497139200, 140],
[1497225600, 200],
[1497312000, 80]
], [
[1597052800, 120],
[1597052800, 80],
[1597052800, 222],
[1597052800, 100]
], [
[1597052800, 120]
]
]
*/