Skip to content

Commit a7da7c8

Browse files
committed
More style fixes
1 parent 4e0a7d5 commit a7da7c8

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"unused": true,
1212
"strict": true,
1313
"maxlen": 80,
14+
"white": true,
1415
"trailing": true,
1516
"curly": false,
1617
"globals": {

algorithms/graph/euler_path.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,29 @@ var Graph = require('../../data_structures/graph');
3232
* @param {Graph} Graph, must be connected and contain at least one vertex.
3333
* @return Object
3434
*/
35-
var eulerEndpoints = function(graph) {
35+
var eulerEndpoints = function (graph) {
3636
var rank = {};
3737
// start -> rank = +1
3838
// middle points -> rank = 0
3939
// finish -> rank = -1
4040

4141
// Initialize ranks to be outdegrees of vertices.
42-
graph.vertices.forEach(function(vertex) {
42+
graph.vertices.forEach(function (vertex) {
4343
rank[vertex] = graph.neighbors(vertex).length;
4444
});
4545

4646
if (graph.directed) {
4747
// rank = outdegree - indegree
48-
graph.vertices.forEach(function(vertex) {
49-
graph.neighbors(vertex).forEach(function(neighbor) {
48+
graph.vertices.forEach(function (vertex) {
49+
graph.neighbors(vertex).forEach(function (neighbor) {
5050
rank[neighbor] -= 1;
5151
});
5252
});
5353
}
5454
else {
5555
// Compute ranks from vertex degree parity values.
5656
var startChosen = false;
57-
graph.vertices.forEach(function(vertex) {
57+
graph.vertices.forEach(function (vertex) {
5858
rank[vertex] %= 2;
5959
if (rank[vertex]) {
6060
if (startChosen) {
@@ -67,7 +67,7 @@ var eulerEndpoints = function(graph) {
6767

6868
var start, finish;
6969

70-
graph.vertices.forEach(function(vertex) {
70+
graph.vertices.forEach(function (vertex) {
7171
if (rank[vertex] == 1) {
7272
if (start !== undefined) {
7373
throw new Error('Duplicate start vertex.');
@@ -104,7 +104,7 @@ var eulerEndpoints = function(graph) {
104104
* @param {Graph}
105105
* @return Array
106106
*/
107-
var eulerPath = function(graph) {
107+
var eulerPath = function (graph) {
108108
if (!graph.vertices.length) {
109109
return [];
110110
}
@@ -116,7 +116,7 @@ var eulerPath = function(graph) {
116116
graph.vertices.forEach(seen.addVertex.bind(seen));
117117

118118
(function dfs(vertex) {
119-
graph.neighbors(vertex).forEach(function(neighbor) {
119+
graph.neighbors(vertex).forEach(function (neighbor) {
120120
if (!seen.edge(vertex, neighbor)) {
121121
seen.addEdge(vertex, neighbor);
122122
dfs(neighbor);
@@ -125,7 +125,7 @@ var eulerPath = function(graph) {
125125
});
126126
}(endpoints.start));
127127

128-
graph.vertices.forEach(function(vertex) {
128+
graph.vertices.forEach(function (vertex) {
129129
if (seen.neighbors(vertex).length < graph.neighbors(vertex).length) {
130130
throw new Error('There is no euler path for a disconnected graph.');
131131
}

data_structures/bst.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ BST.prototype.insert = function (value, parent) {
6767
}
6868

6969
var child = this._comparator.lessThan(value, parent.value) ? 'left' : 'right';
70-
if (parent[child])
70+
if (parent[child]) {
7171
this.insert(value, parent[child]);
72-
else {
72+
} else {
7373
parent[child] = new Node(value, parent);
7474
this._size++;
7575
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"coveralls": "^2.10.0",
1212
"istanbul": "^0.2.10",
1313
"jshint": "~2.4.4",
14+
"jscs": "1.4.5",
1415
"mocha": "^1.20.0"
1516
},
1617
"repository": {

test/algorithms/graph/euler_path.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,35 @@ var eulerPath = require('../../../algorithms/graph/euler_path'),
2727
assert = require('assert');
2828

2929

30-
var verifyEulerPath = function(graph, trail) {
30+
var verifyEulerPath = function (graph, trail) {
3131
var visited = new Graph(graph.directed);
3232
graph.vertices.forEach(visited.addVertex.bind(visited));
3333

34-
trail.slice(1).reduce(function(previous, current) {
34+
trail.slice(1).reduce(function (previous, current) {
3535
assert(graph.edge(previous, current));
3636
assert(!visited.edge(previous, current));
3737
visited.addEdge(previous, current);
3838
return current;
3939
}, trail[0]);
4040

41-
graph.vertices.forEach(function(vertex) {
41+
graph.vertices.forEach(function (vertex) {
4242
assert.equal(graph.neighbors(vertex).length,
4343
visited.neighbors(vertex).length);
4444
});
4545
};
4646

4747

48-
var graphFromEdges = function(directed, edges) {
48+
var graphFromEdges = function (directed, edges) {
4949
var graph = new Graph(directed);
50-
edges.forEach(function(edge) {
50+
edges.forEach(function (edge) {
5151
graph.addEdge(edge[0], edge[1]);
5252
});
5353
return graph;
5454
};
5555

5656

57-
describe('Euler Path', function() {
58-
it('should compute Euler tour over the undirected graph', function() {
57+
describe('Euler Path', function () {
58+
it('should compute Euler tour over the undirected graph', function () {
5959
var graph = graphFromEdges(false, [[1, 2],
6060
[1, 5],
6161
[1, 7],
@@ -76,7 +76,7 @@ describe('Euler Path', function() {
7676
assert.equal(trail[0], trail.slice(-1)[0]);
7777
});
7878

79-
it('should compute Euler walk over the undirected graph', function() {
79+
it('should compute Euler walk over the undirected graph', function () {
8080
var graph = graphFromEdges(false, [[1, 2],
8181
[1, 5],
8282
[1, 7],
@@ -99,7 +99,7 @@ describe('Euler Path', function() {
9999
assert.equal(endpoints[1], 8);
100100
});
101101

102-
it('should compute Euler tour over the directed graph', function() {
102+
it('should compute Euler tour over the directed graph', function () {
103103
var graph = graphFromEdges(true, [[0, 1],
104104
[1, 2],
105105
[2, 0],
@@ -115,7 +115,7 @@ describe('Euler Path', function() {
115115
assert.equal(trail[0], trail.slice(-1)[0]);
116116
});
117117

118-
it('should compute Euler walk over the directed graph', function() {
118+
it('should compute Euler walk over the directed graph', function () {
119119
var graph = graphFromEdges(true, [[5, 0],
120120
[0, 2],
121121
[2, 4],
@@ -127,20 +127,20 @@ describe('Euler Path', function() {
127127
assert.deepEqual(trail, [5, 3, 1, 5, 0, 2, 4, 0]);
128128
});
129129

130-
it('should return single-vertex-trail for an isolated vertex', function() {
130+
it('should return single-vertex-trail for an isolated vertex', function () {
131131
var graph = new Graph();
132132
graph.addVertex('loner');
133133
var trail = eulerPath(graph);
134134
assert.deepEqual(trail, ['loner']);
135135
});
136136

137-
it('should return empty trail for an empty graph', function() {
137+
it('should return empty trail for an empty graph', function () {
138138
var graph = new Graph();
139139
var trail = eulerPath(graph);
140140
assert.deepEqual(trail, []);
141141
});
142142

143-
it('should raise an error if there is no Euler path', function() {
143+
it('should raise an error if there is no Euler path', function () {
144144
var graph = graphFromEdges(false, [[0, 1], [2, 3]]);
145145
assert.throws(eulerPath.bind(graph));
146146
graph = graphFromEdges(false, [[0, 1],

0 commit comments

Comments
 (0)