Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ecc151

Browse files
committed
fix(build): handle jscs errors
1 parent c1a1b2f commit 0ecc151

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/graphs/others/tarjan-connected-components.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(function (exports) {
2+
'use strict';
23

3-
/**
4+
/**
45
* Tarjan's algorithm for finding the connected components in a graph.<br><br>
56
* Time complexity: O(|E| + |V|) where E is a number of edges and |V|
67
* is the number of nodes.
@@ -30,15 +31,15 @@
3031
const onStack = {};
3132
const result = [];
3233
const stack = [];
33-
let index = 1;
34+
var index = 1;
3435

35-
const connectedComponent = node => {
36+
const connectedComponent = function (node) {
3637
stack.push(node);
3738
onStack[node] = true;
3839
indexes[node] = index;
3940
lowIndexes[node] = index;
4041
index += 1;
41-
graph[node].forEach(n => {
42+
graph[node].forEach(function (n) {
4243
if (indexes[n] === undefined) {
4344
connectedComponent(n);
4445
lowIndexes[node] = Math.min(lowIndexes[n], lowIndexes[node]);
@@ -49,7 +50,7 @@
4950
// This is a "root" node
5051
const cc = [];
5152
if (indexes[node] === lowIndexes[node]) {
52-
let current;
53+
var current;
5354
do {
5455
current = stack.pop();
5556
onStack[current] = false;
@@ -60,7 +61,11 @@
6061
};
6162

6263
Object.keys(graph)
63-
.forEach(n => !indexes[n] && connectedComponent(n));
64+
.forEach(function (n) {
65+
if (!indexes[n]) {
66+
connectedComponent(n);
67+
}
68+
});
6469

6570
return result;
6671
}

test/graphs/others/tarjan-connected-components.spec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ var cyclicGraph = {
1616
v5: ['v1']
1717
};
1818

19-
2019
describe('Tarjan\'s algorithm for finding connected components', function () {
2120
'use strict';
2221
it('should be defined', function () {
@@ -31,8 +30,7 @@ describe('Tarjan\'s algorithm for finding connected components', function () {
3130
expect(tj(nonConnected)).toEqual([['v1'], ['v2'], ['v3'], ['v4'], ['v5']]);
3231
});
3332

34-
it('should workw ith cycles', () => {
33+
it('should workw ith cycles', function () {
3534
expect(tj(cyclicGraph)).toEqual([['v5', 'v4', 'v3', 'v2', 'v1']]);
3635
});
37-
3836
});

0 commit comments

Comments
 (0)