Skip to content

Commit aa946a1

Browse files
authored
Merge pull request algorithm-visualizer#153 from Howon/gh-pages
changed to deep comparison for sanity
2 parents 11966d0 + 4738d5f commit aa946a1

File tree

8 files changed

+27
-27
lines changed

8 files changed

+27
-27
lines changed

algorithm/cryptography/affine_cipher/basic/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function decrypt (cypherText) {
4242
var plainText = '';
4343
var aInverse = (function () {
4444
for (var i = 1; i < N; i++) {
45-
if ( ((keys.a * i).mod (N)) == 1 ) {
45+
if ( ((keys.a * i).mod (N)) === 1 ) {
4646
return i;
4747
}
4848
}

algorithm/dp/max_sum_path/basic/code.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ function update(i, j, value) {
99
}
1010
for (var i = 0; i < N; i++) {
1111
for (var j = 0; j < M; j++) {
12-
if (i == 0 && j == 0) {
12+
if (i === 0 && j === 0) {
1313
update(i, j, D[i][j]);
14-
} else if (i == 0) {
14+
} else if (i === 0) {
1515
tracer._select(i, j - 1);
1616
update(i, j, DP[i][j - 1] + D[i][j]);
1717
tracer._deselect(i, j - 1);
18-
} else if (j == 0) {
18+
} else if (j === 0) {
1919
tracer._select(i - 1, j);
2020
update(i, j, DP[i - 1][j] + D[i][j]);
2121
tracer._deselect(i - 1, j);

algorithm/graph_search/bfs/shortest_path/code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ var s = Integer.random(0, G.length - 1); // s = start node
2727
var e; // e = start node
2828
do {
2929
e = Integer.random(0, G.length - 1);
30-
} while (s == e);
30+
} while (s === e);
3131
var MAX_VALUE = Infinity;
3232
logger._print('finding the shortest path from ' + s + ' to ' + e);
3333
var minWeight = BFS(s);
34-
if (minWeight == MAX_VALUE) {
34+
if (minWeight === MAX_VALUE) {
3535
logger._print('there is no path from ' + s + ' to ' + e);
3636
} else {
3737
logger._print('the shortest path from ' + s + ' to ' + e + ' is ' + minWeight);

algorithm/graph_search/bridges/efficient/code.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var util = function (u, disc, low, parent) {
88
//u is the node that is currently being processed in the DFS (depth-first search)
99
//disc is the numbering of the vertices in the DFS, starting at 0
1010
//low[v] is the lowest numbered vertex that can be reached from vertex v along the DFS
11-
//parent is the node that u came from
11+
//parent is the node that u came from
1212
logger._print ('');
1313
logger._print ('Visiting node ' + u);
1414
graphTracer._visit (u)._wait ();
@@ -28,10 +28,10 @@ var util = function (u, disc, low, parent) {
2828
}
2929

3030
adj [u].forEach (function (v) {
31-
if (disc [v] > -1 && v == parent) {
31+
if (disc [v] > -1 && v === parent) {
3232
trace(v);
3333
logger._print (u + '\'s neighbor ' + v + ' is u\'s parent. Not visiting it.');
34-
34+
3535
}
3636
else if (disc[v] > -1 && v != parent) {
3737
trace(v);
@@ -42,7 +42,7 @@ var util = function (u, disc, low, parent) {
4242
}
4343
}
4444

45-
if (disc[v] == -1) {
45+
if (disc[v] === -1) {
4646
trace(v);
4747
logger._print (u + '\'s neighbor ' + v + ' has not been visited yet');
4848

@@ -54,18 +54,18 @@ var util = function (u, disc, low, parent) {
5454
logger._print ('Setting low [' + u + '] to ' + Math.min (low [u], low [v]));
5555
low [u] = Math.min (low [u], low [v]);
5656

57-
if (low [v] == disc [v]) {
57+
if (low [v] === disc [v]) {
5858
logger._print ('low [' + v + '] == disc [' + v + '], low[' + v + ']=' + low[v] + ', disc[' + v + ']=' + disc[v]);
5959
logger._print (u + ' -> ' + v + ' is a bridge. Adding ' + u + '->' + v + 'to the set of bridges found');
6060
bridges.push ([u, v]);
6161
}
6262
}
63-
63+
6464
});
6565
};
6666

6767
(function findBridges (graph) {
68-
68+
6969
var disc = filledArray (graph.length, -1);
7070
var low = filledArray (graph.length, -1);
7171

@@ -92,7 +92,7 @@ var util = function (u, disc, low, parent) {
9292

9393
logger._print ('Starting the main for loop (for each node)');
9494
for (var v = 0; v < graph.length; v++) {
95-
if (disc[v] == -1) {
95+
if (disc[v] === -1) {
9696
logger._print (v + ' has not been visited yet. Calling util (' + v + ', [' + disc + '], [' + low + '],' + v + ') from the for loop');
9797
util (v, disc, low, v);
9898
logger._print ('Returned in for loop after util (' + v + ', [' + disc + '], [' + low + '], [' + v + '])');

algorithm/graph_search/dfs/shortest_path/code.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function DFS(node, parent, weight) { // node = current node, parent = previous node
22
if (minWeight < weight) return;
3-
if (node == e) {
3+
if (node === e) {
44
tracer._visit(node, parent, weight)._wait();
55
if (minWeight > weight) {
66
minWeight = weight;
@@ -24,14 +24,14 @@ var s = Integer.random(0, G.length - 1); // s = start node
2424
var e; // e = end node
2525
do {
2626
e = Integer.random(0, G.length - 1);
27-
} while (s == e);
27+
} while (s === e);
2828
var MAX_VALUE = Infinity;
2929
var minWeight = MAX_VALUE;
3030
logger._print('finding the shortest path from ' + s + ' to ' + e);
3131
var D = []; // D[i] indicates whether the i-th node is discovered or not
3232
for (var i = 0; i < G.length; i++) D.push(false);
3333
DFS(s, undefined, 0);
34-
if (minWeight == MAX_VALUE) {
34+
if (minWeight === MAX_VALUE) {
3535
logger._print('there is no path from ' + s + ' to ' + e);
3636
} else {
3737
logger._print('the shortest path from ' + s + ' to ' + e + ' is ' + minWeight);

algorithm/graph_search/dijkstra/shortest_path/code.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Dijkstra(start, end) {
1515
minIndex = i;
1616
}
1717
}
18-
if (minDistance == MAX_VALUE) break; // If there is no edge from current node, jump out of loop
18+
if (minDistance === MAX_VALUE) break; // If there is no edge from current node, jump out of loop
1919
D[minIndex] = true;
2020
tracerS._select(minIndex);
2121
tracer._visit(minIndex)._wait();
@@ -32,7 +32,7 @@ function Dijkstra(start, end) {
3232
}
3333
tracer._leave(minIndex)._wait();
3434
}
35-
if (S[end] == MAX_VALUE) {
35+
if (S[end] === MAX_VALUE) {
3636
logger._print('there is no path from ' + start + ' to ' + end);
3737
} else {
3838
logger._print('the shortest path from ' + start + ' to ' + end + ' is ' + S[end]);
@@ -43,6 +43,6 @@ var s = Integer.random(0, G.length - 1); // s = start node
4343
var e; // e = end node
4444
do {
4545
e = Integer.random(0, G.length - 1);
46-
} while (s == e);
46+
} while (s === e);
4747
logger._print('finding the shortest path from ' + s + ' to ' + e)._wait();
4848
Dijkstra(s, e);

algorithm/graph_search/floyd_warshall/shortest_paths/code.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ function FloydWarshall() {
1616
// If there is a shorter path using k, use it instead
1717
for (var k = 0; k < G.length; k++) {
1818
for (i = 0; i < G.length; i++) {
19-
if (k == i) continue;
19+
if (k === i) continue;
2020
tracer._visit(k, i)._wait();
2121
for (j = 0; j < G.length; j++) {
22-
if (i == j || j == k) continue;
22+
if (i === j || j === k) continue;
2323
tracer._visit(j, k)._wait();
2424
if (S[i][j] > S[i][k] + S[k][j]) {
2525
tracer._visit(j, i, S[i][j])._wait();
@@ -33,7 +33,7 @@ function FloydWarshall() {
3333
}
3434
for (i = 0; i < G.length; i++)
3535
for (j = 0; j < G.length; j++)
36-
if (S[i][j] == MAX_VALUE) logger._print('there is no path from ' + i + ' to ' + j);
36+
if (S[i][j] === MAX_VALUE) logger._print('there is no path from ' + i + ' to ' + j);
3737
else logger._print('the shortest path from ' + i + ' to ' + j + ' is ' + S[i][j]);
3838
}
3939
var MAX_VALUE = Infinity;

algorithm/sorting/cycle/basic/code.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ for (var cycleStart = 0; cycleStart <= N - 2; cycleStart++) {
1919
}
2020

2121
// if the item is already there, this is not a circle
22-
if (pos == cycleStart) {
22+
if (pos === cycleStart) {
2323
tracer._deselect(cycleStart);
2424
continue;
2525
}
2626

2727
// otherwise put the item there or right after any duplicates
28-
while (item == D[pos]) {
28+
while (item === D[pos]) {
2929
pos++;
3030
}
3131

@@ -46,7 +46,7 @@ for (var cycleStart = 0; cycleStart <= N - 2; cycleStart++) {
4646
tracer._denotify(pos)._denotify(cycleStart);
4747

4848
// rotate the rest of the cycle
49-
while (pos != cycleStart) {
49+
while (pos !== cycleStart) {
5050
pos = cycleStart;
5151

5252
for (i = cycleStart + 1; i <= N - 1; i++) {
@@ -56,7 +56,7 @@ for (var cycleStart = 0; cycleStart <= N - 2; cycleStart++) {
5656
}
5757
}
5858

59-
while (item == D[pos]) {
59+
while (item === D[pos]) {
6060
pos++;
6161
}
6262

0 commit comments

Comments
 (0)