選擇題主要不會的是Promise和一些Web安全
的知識。node
編程題:編程
bfs
代碼:安全
function bfs(node) { var arr = []; if(node != null) { var queue = []; queue.unshift(node); while(queue.length != 0) { var item = queue.shift(); arr.push(item); var children = item.children; for(var i=0; i<children.length; ++i) { queue.push(children[i]); } } } return arr; }
建樹、dfs、遞歸
輸入:code
[ { id:1, value:'1', parentId:3 }, { id:2, value:'2', parentId:0 }, { id:3, value:'3', parentId:0 }, { id:4, value:'4', parentId:2 }, { id:5, value:'5', parentId:2 } ]
輸出:遞歸
{ children: [ { children: [ { children:[], id: 4, value: '4' }, { children:[], id: 5, value: '5' } ], id: 2, value: '2' }, { children: [ { children:[], id: 1, value: '1' } ], id: 3, value: '3', } ], id: 0, value: '0' }
代碼:get
function bfs(node) { var arr = []; if(node != null) { var queue = []; queue.unshift(node); while(queue.length != 0) { var item = queue.shift(); arr.push(item); var children = item.children; for(var i=0; i<children.length; ++i) { queue.push(children[i]); } } } return arr; }