Results 5 comments of zedyang

深度优先遍历,遍历的时候得到每个node的父ids,最后再遍历一次拿到父 ids ``` const data = [{ id: '1', name: 'test1', children: [ { id: '11', name: 'test11', children: [ { id: '111', name: 'test111' }, { id: '112', name:...

const a = '1, 2, 3, 5, 7, 8, 10' function bar(str) { const strList = str.split(', ') let start = strList[0] let result = [] for(let i = 0;...

利用时间戳,➕24 * 60 * 60 * 1000,得到下一天时间戳。 ``` var start = '2015-2-8' var end = '2015-3-3' function getDate(start, end) { const startDate = new Date(start) const endDate = new Date(end)...

从牌桌拿回的时候,先要把最后一张置顶,也就是 `result.unshift(result.pop())`。 之后就是基本操作 ``` var data = [1,2,3,4,5,6,7,8,9,10,11,12,13] function bar(data) { let result = [] for(let i = data.length - 1; i >= 0; i--) { if(result.length === 0 ||...

利用对象是引用类型,直接通过pId找到父元素 ``` var data = [{id: 1}, {id: 2, pId: 1},{id: 3, pId: 2}] function bar() { let dataNoRepeat = data.reduce((curr, acc) => { curr[acc.id] = acc return curr },...