const arrays = [[1, 3, 5, 7, 9, 11, 12], [1, 2, 3, 4, 5, 10, 12]]
console.log(arrays.flat(Infinity).reduce((acc, curr) => !acc.includes(curr) ? [...acc, curr] : acc , []).sort((a, b) => a - b))
Андрей УстиновМастер (2150)
5 месяцев назад
Ой. понял ошибку. там надо массивы объединить. вот правильный код.
const array1 = [1, 3, 5, 7, 9, 11, 12]
const array2 = [1, 2, 3, 4, 5, 10, 12]
console.log(array1.concat(array2).reduce((acc, curr) => !acc.includes(curr) ? [...acc, curr] : acc , []).sort((a, b) => a - b))
* [1, 3, 5, 7, 9, 11, 12], [1, 2, 3, 4, 5, 10, 12] -> [1, 2, 3, 4, 5, 7, 9, 10, 11, 12]