/**
* 分组排序
*/
const sortByKey = (array: object[], key: string) => {
return array.reduce((total, next) => {
const index = total.findIndex((item, index, self) => {
return item[key] === next[key];
});
return index === -1
? total.push(next) && total
: total.splice(index, 0, next) && total;
}, []);
};
/**
* 计算合并
*/
const merge = (list: any[], key: string): any => {
const len = list.length;
const rowsSpan = {};
let step = 0;
for (let i = 0; i < len - 1; i++) {
if (list[i][key] === list[i + 1][key]) {
if (!rowsSpan[step]) {
rowsSpan[step] = 1;
}
rowsSpan[step]++;
} else {
step = i + 1;
rowsSpan[step] = 1;
}
}
return rowsSpan;
};