Using a hash table, we're able to set each particular vertex as a hash key, and its value pairing to an array of adjacent vertices. We can use the default hash table data structure
that comes with the language:
xxxxxxxxxx
class Graph {
constructor() {
this.adjacencyList = new Map();
// we can iterate through keys with Map
// and use objects and functions as keys
}
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment