const calendarData = [
[null, null, 1, 2, 3],
[4, 5, 6, 7, 8],
[9, 10, 11, null, null],
[null, null, null, null, null],
]
надо получить такой массив
const newCalendarData = [
[null, null, 1, 2, 3],
[4, 5, 6, 7, 8],
[9, 10, 11],
]
1 ответ
const calendarData = [
[null, null, 1, 2, 3],
[4, 5, 6, 7, 8],
[9, 10, 11, null, null],
[null, null, null, null, null]
];
const f = calendarData
.map((item) => item.filter(Boolean).length && item)
.filter(Boolean)
.map((item) =>
item[item.length - 1] !== null ? item : item.filter(Boolean)
);
console.log(f);
// const newCalendarData = [
// [null, null, 1, 2, 3],
// [4, 5, 6, 7, 8],
// [9, 10, 11],
// ]