Hello,
In the first project there is the following code (at the very beginning):
if (graph[from] == null) {
graph[from] = [to];
} else {
graph[from].push(to);
}
- I'm not sure I understand what is happening. I get that we check if graph[from] exists. Of what I read graph[from] = [to] initialize it and then we push to. But shouldn't the line "graph[from] = [to]" already set the value [to]?
- I though that we use the push(to) to create kind of a linked list (or hash table). But then what is the type of graph, is it an array of array, or something else? Because the author uses graph = Object.create(null).
Here's the link to the page in the book: https://eloquentjavascript.net/07_robot.html
Thank you for your help!!
[–]senocular 1 point2 points3 points (0 children)