Map去重
wrapData = (array = []) => { const map = new Map(); for (let index = 0; index < array.length; index++) { const element = array[index]; const { category } = element;// let fix = []; if (map.has(category)) fix = map.get(category); fix.push(element); map.set(category, fix); } const fix = [...map.values()].map(v => { let _type = v[0].category; let _percent = 0; let _value = 0; for (let index = 0; index < v.length; index++) { const element = v[index]; _percent += element.percent; _value += element.y; } return { x: _type, category: _type, percent: _percent, y: _value }; }); return fix; }
未闻花名