Results 6 comments of leige

function test(n){ let count = 0; while(n>0){ if(n.toString().indexOf('1')>-1){ count ++;} n--; } return count; }

let tanslate = list => { // 先建立每一项的id和数据的对应关系 let map=new Map(); list.map(el=>{map.set(el.id,el)}); let res=[]; for(let item of list){ // 把根节点存进数组 if(!item.parentId){ res.push(item); continue; } //遍历过程中,找到item的parentId,在映射表中直接取出这个元素,把item推进它的children。 if(map.has(item.parentId)){ let parent=map.get(item.parentId); parent.children?parent.children.push(item):parent.children=[item]; }...

function f(str){ let hash={}; str.split("").map(el=>{ hash[el]?hash[el].push(el):hash[el]=[el]; }); reurn [...hash['黄'],...hash['红'],...hash['蓝']].join(""); }

> > > 哦 > > > > > > 今天又是流下没有技术的眼泪的一天? > > 过分了昂 流下没有技术眼泪的第218天

function f(arr){ return [...new Set(arr.map(el=>JSON.stringify(el)))].map(el=>JSON.parse(el)) }