When trying to test whether you've managed to figure out an algorithm's implementation, it's darn difficult to judge using standard console output tools. Here's a template for generating source files that can be used to visually validate that you're code Did The Right Thing.
npm -s run dev > simple.dot
dot -Tpdf -o simple.pdf simple.dot
open -a "Preview" simple.pdf
npm -s run dev > simple.dot && dot -Tpdf -o simple.pdf simple.dot && open -a "Preview" simple.pdf