Skip to content

Instantly share code, notes, and snippets.

@RubyTuesdayDONO
RubyTuesdayDONO / gist:5006455
Last active May 15, 2024 22:22 — forked from six8/gist:1732686
logic revisions to pass test case
// Dependency resolution, adapted from https://gist.github.com/1232505/f16308bc14966c8d003c2686b1c258ec41303c1f
function resolve(graph) {
var sorted = [], // sorted list of IDs ( returned value )
visited = {}; // hash: id of already visited node => true
// 2. topological sort
Object.keys(graph).forEach(function visit(name, ancestors) {
if (!Array.isArray(ancestors)) ancestors = [];
ancestors.push(name);
visited[name] = true;