JavaScript kata for directed acyclic graph data structure