Find order to install dependencies
Heres how I did it properly with topological sorting. Each key of the object is a vertex on a graph, the value dependencies are the adjacent vertices. https://www.youtube.com/watch?v=ddTC4Zovtbc

var deps = {
    p1: ['p2', 'p3'],
    p2: [],
    p3: ['p3']
};

function depSort(deps) {
    var visited = [];
    var sorted = [];

    for (var dep in deps) {
        if (!visited[dep]) {
            depSortUtil(dep, visited, sorted);
        }
    }

    return sorted;
}

function depSortUtil(dep, visited, sorted) {
    visited[dep] = true;

    for (var i = 0; i &lt; deps[dep].length; i++) {
        if (!visited[deps[dep][i]]) {
            depSortUtil(deps[dep][i], visited, sorted);
        }
    }
    sorted.push(dep);
}

console.log(depSort(deps));