Topologically sort directed acyclic graphs (such as dependency lists) in javascript