编程思想,看来我还是B格不够,底层是地基啊!
编写一个函数, 按照name去重,如果存在多项name 相同的,取price最大的一项,然后按照price从小到大排序输出
const data = [{ name: 'aaa', price: 40}, { name: 'bbb', price: 10 }, { name: 'aaa', price: 20 }, { name: 'ccc', price: 2 }, { name: 'ddd', price: 31 },{ name: 'eee', price: 1 },{ name: 'fff', price: 4} ];
关系型数组转化为树形结果对象
var obj = [ { id:3, parent:2 }, { id:1, parent:null }, { id:2, parent:1 }, { id:4, parent:1 },]期望返回{ obj: { id: 1, parent: null, children: [{ id: 2, parent: 1, children: [{ id: 3, parent: 2 }] }, { id:4, parent:1 children: [] }] } }![在这里插入图片描述](https://img-blog.csdnimg.cn/20201105015040232.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNDk1Nzc1,size_16,color_FFFFFF,t_70)