Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ecc151

Browse files
committed
fix(build): handle jscs errors
1 parentc1a1b2f commit0ecc151

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
constonStack={};
3132
constresult=[];
3233
conststack=[];
33-
letindex=1;
34+
varindex=1;
3435

35-
constconnectedComponent=node=>{
36+
constconnectedComponent=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
constcc=[];
5152
if(indexes[node]===lowIndexes[node]){
52-
letcurrent;
53+
varcurrent;
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
returnresult;
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)

[8]ページ先頭

©2009-2025 Movatter.jp