Skip to content

Commit

Permalink
Merge pull request #412 from RohitPaul0007/patch-55
Browse files Browse the repository at this point in the history
Update init-order.js
  • Loading branch information
rustedgrail authored Sep 11, 2023
2 parents 838ecce + d021db8 commit 6527958
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/order/init-order.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var util = require("../util");
let util = require("../util");

module.exports = initOrder;

Expand All @@ -16,20 +16,20 @@ module.exports = initOrder;
* the order of its nodes.
*/
function initOrder(g) {
var visited = {};
var simpleNodes = g.nodes().filter(v => !g.children(v).length);
var maxRank = Math.max(...simpleNodes.map(v => g.node(v).rank));
var layers = util.range(maxRank + 1).map(() => []);
let visited = {};
let simpleNodes = g.nodes().filter(v => !g.children(v).length);
let maxRank = Math.max(...simpleNodes.map(v => g.node(v).rank));
let layers = util.range(maxRank + 1).map(() => []);

function dfs(v) {
if (visited[v]) return;
visited[v] = true;
var node = g.node(v);
let node = g.node(v);
layers[node.rank].push(v);
g.successors(v).forEach(dfs);
}

var orderedVs = simpleNodes.sort((a, b) => g.node(a).rank - g.node(b).rank);
let orderedVs = simpleNodes.sort((a, b) => g.node(a).rank - g.node(b).rank);
orderedVs.forEach(dfs);

return layers;
Expand Down

0 comments on commit 6527958

Please sign in to comment.