Topological sort in JavaScript

Here's how to implement Kahn's algorithm for topological sort in JavaScript. Topological sort (or topo-sort) is often used to schedule tasks that must be completed in a certain order. A common example is a build system where Module A must load before Module B, which depends on Module C, etc.