/**
* @param {Array} tableData2 要处理的数组 [{id:1,name:'小二',age:18},{id:1,name:'小二',age:16},{id:1,name:'小二',age:18}]
* @param {string} key 要匹配的键 age
* @returns {Array} 返回处理好的数组 [{id:1,name:'小二',age:18},{id:1,name:'小二',age:18},{id:1,name:'小二',age:16}]
* @description 把数组中拥有相同值的部分放在一起
*/
export function arrMergeSort(tableData2=[],key='') {
let cache = {}; //存储的是键是zhuanye 的值,值是zhuanye 在indeces中数组的下标
let indices = []; //数组中每一个值是一个数组,数组中的每一个元素是原数组中相同zhuanye的下标
tableData2.map((item,index)=>{
let zhuanye = item[key];
let _index = cache[zhuanye];
if(_index!==undefined){
indices[_index].push(index)
}else{
cache[zhuanye] = indices.length
indices.push([index])
}
})
let result = [];
indices.map((item)=>{
item.map((index)=>{
result.push(tableData2[index])
})
})
return result
}