function sortData(list) {
let result = []
const colorGroup = {}
for (const item of list) {
if (!colorGroup[item.color]) {
colorGroup[item.color] = []
}
colorGroup[item.color].push(item)
}
const colorIds = []
for (const colorId in colorGroup) {
colorIds.push(colorId)
colorGroup[colorId] = colorGroup[colorId].sort((a, b) => a.size - b.size)
}
const sortColorIds = colorIds.sort((a, b) => b - a)
for (const colorId of sortColorIds) { result = [...result, ...colorGroup[colorId]] }
return result
}