я нашел уникальные id (uniqColumns). по ним пробежался.
const separationData = uniqColumns?.map(item => {
const res = []
const arr = dataPrepare?.filter(s => s[`${Object.keys(s).find((key) => key.startsWith("id"))}`] === item)
res.push(arr)
return res
})
const res: DataTypeSelect[] = [];
const itemCheck = (item: any) => {
if (res.indexOf(item.classifId) === -1) {
res.push(item.classifId);
return true
}
return false;
}
const data = dataSource ? dataSource?.map(item => {
return ({
key: item.classifId,
classifName: item.classifName,
classifId: item.classifId
})
}).filter(item => itemCheck(item)) : []
export type Compare = {
channelid: number,
childrenHash: Child[]
}
export type Child = {
id: number, hash: string
}
export const comparsion = (data: Compare[]) => {
const res = data?.map((n: { childrenHash: any[] }) => {
const ids = Object.values(n.childrenHash.reduce((acc, m) => ((acc[m.hash] ??= []).push(m.id), acc), {})).filter((m:any) => m.length > 1);
return {
...n,
childrenHash: ids.length ? ids : null,
};
})
return res
}