Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. // getChildren(win) - returns array of windows that are child to `win`
  2. // isTrue(win) - just a random callback
  3.  
  4. function recurseDFS(win) {
  5. // depth first
  6. let coll = [];
  7. coll.push(isTrue(win));
  8. let children = getChildren(win);
  9. for (let child of children) {
  10. coll.push(...recurseDFS(child));
  11. }
  12. return coll;
  13. }
  14.  
  15. function recurseBFS(win) {
  16. // breadth first
  17. let coll = [];
  18. let todo = [win];
  19.  
  20. while (todo.length) {
  21. let cur = todo.shift();
  22. coll.push(isTrue(cur));
  23. todo.push(...getChildren(cur));
  24. }
  25.  
  26. return coll;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement