Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 8ed94a2

Browse files
committed
Some more cleanup
1 parent 1241866 commit 8ed94a2

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

runestone/parsons/js/dagHelpers.js

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
1+
"use strict";
12
/**
23
* This file adapted from JSNetworkX: https://github.com/fkling/JSNetworkX
34
* Copyright (C) 2012 Felix Kling <felix.kling@gmx.net>
45
* JSNetworkX is distributed with the BSD license
56
*/
67

7-
function isObjectLike(value) {
8-
return !!value && typeof value == 'object';
9-
}
10-
11-
function isBoolean(value) {
12-
var boolTag = '[object Boolean]';
13-
return value === true || value === false || (isObjectLike(value) && Object.prototype.toString.call(value) == boolTag);
14-
}
15-
16-
function nodesAreEqual(a, b) {
17-
return a === b || typeof a === 'object' && a.toString() === b.toString();
18-
}
19-
208
export function hasPath(G, {source, target}) {
21-
try {
22-
shortestPath(G, {source, target});
23-
} catch(error) {
24-
if (error instanceof JSNetworkXNoPath) {
25-
return false;
26-
}
27-
throw error;
9+
try {
10+
bidirectionalShortestPath(G, source, target)
11+
} catch(error) {
12+
if (error instanceof JSNetworkXNoPath) {
13+
return false;
2814
}
29-
return true;
15+
throw error;
3016
}
17+
return true;
18+
}
3119

32-
function shortestPath(G, {source, target, weight}={}) {
33-
return bidirectionalShortestPath(G, source, target);
20+
function nodesAreEqual(a, b) {
21+
return a === b || typeof a === 'object' && a.toString() === b.toString();
3422
}
3523

3624
function bidirectionalShortestPath(G, source, target) {
@@ -107,7 +95,7 @@ function bidirectionalPredSucc(G, source, target) {
10795
}
10896
}
10997
}
110-
throw new JSNetworkXNoPath('No path between ' + source + ' and ' + target + ".");
98+
throw new JSNetworkXNoPath('No path between ' + source + ' and ' + target + '.');
11199
}
112100

113101
function topologicalSort(G, optNbunch) {
@@ -389,3 +377,13 @@ class JSNetworkXNoPath extends JSNetworkXUnfeasible {
389377
this.name = 'JSNetworkXNoPath';
390378
}
391379
}
380+
381+
// functions from LoDash, needed by functions from JSNetworkX
382+
function isObjectLike(value) {
383+
return !!value && typeof value == 'object';
384+
}
385+
386+
function isBoolean(value) {
387+
var boolTag = '[object Boolean]';
388+
return value === true || value === false || (isObjectLike(value) && Object.prototype.toString.call(value) == boolTag);
389+
}

0 commit comments

Comments
 (0)