title: JavaScript - Graph traversal - Get nodes in order (nearest first) from a starting node
body: <p>I have got a graph which looks like this :</p>
  
  <pre><code>root : {
      nodeType : "root",
      children: [
      "A",
      "B",
      "C"
      ]
  }
  nodes : [
  "A": {
      nodeType : "node",
      children: [
      "D",
      "E"
      ]
  },
  "B": {
      nodeType : "node",
      children: [
      "D",
      "F"
      ]
  },
  "C": {
      nodeType : "leaf"
  },
  "D": {
      nodeType : "node",
      children: [
      "G"
      ]
  },
  "E": {
      nodeType : "leaf"
  },
  "F": {
      nodeType : "leaf"
  },
  "G": {
      nodeType : "leaf"
  },
  ]
  </code></pre>
  
  <p>I need to write a javascript function which, given a starting point (for example "B"), would traverse the graph in a closest-to-starting-point-priority way. For example for B, it would get children D, F, then root, then siblings B, C, then granchild G, then childs of B and C and so on.</p>
  
  <p>Even just having the algorithm would be fine</p>
  
  <p>PS: I know that I could use a dijkstra in there but I don't really figure out how</p>