X Tutup
Skip to content

Commit 2f20f81

Browse files
committed
Update code style
1 parent 8fd4d16 commit 2f20f81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+212
-187
lines changed

.jscsrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"requireSpacesInFunctionExpression": {
55
"beforeOpeningCurlyBrace": true
66
},
7+
"disallowMultipleVarDecl": true,
78
"requireSpacesInsideObjectBrackets": "allButNested",
89
"disallowSpacesInsideArrayBrackets": true,
910
"disallowSpacesInsideParentheses": true,

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ gulp.task('jscs', function () {
2828
.pipe(jscs());
2929
});
3030

31-
gulp.task('build', ['lint', 'test']);
31+
gulp.task('build', ['lint', 'jscs', 'test']);

src/compression/runlength/runlength.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* This takes O(n).
1515
*/
1616
function convertToAscii(str) {
17-
var result = '',
18-
currentChar = '',
19-
i = 0;
17+
var result = '';
18+
var currentChar = '';
19+
var i = 0;
2020
for (; i < str.length; i += 1) {
2121
currentChar = str[i].charCodeAt(0).toString(2);
2222
if (currentChar.length < 8) {
@@ -34,11 +34,11 @@
3434
* Takes O(n^2).
3535
*/
3636
function runLength(vector) {
37-
var result = '',
38-
zeros = 0,
39-
zerosTemp = '',
40-
wordLength = 0,
41-
i = 0;
37+
var result = '';
38+
var zeros = 0;
39+
var zerosTemp = '';
40+
var wordLength = 0;
41+
var i = 0;
4242
for (; i < vector.length; i += 1) {
4343
if (vector[i] === '0') {
4444
zeros += 1;

src/data-structures/binary-search-tree.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@
254254
}
255255

256256
if (node._left && node._right) {
257-
var min = this._findMin(node._right),
258-
temp = node.value;
257+
var min = this._findMin(node._right);
258+
var temp = node.value;
259259

260260
node.value = min.value;
261261
min.value = temp;
@@ -362,9 +362,9 @@
362362
if (!root) {
363363
return 0;
364364
}
365-
var leftHeight = this._getHeight(root._left),
366-
rightHeight = this._getHeight(root._right),
367-
path = leftHeight + rightHeight + 1;
365+
var leftHeight = this._getHeight(root._left);
366+
var rightHeight = this._getHeight(root._right);
367+
var path = leftHeight + rightHeight + 1;
368368
return Math.max(path, getDiameter(root._left), getDiameter(root._right));
369369
}.bind(this);
370370
return getDiameter(this._root);
@@ -401,10 +401,10 @@
401401

402402
exports.BinaryTree.prototype._lowestCommonAncestor =
403403
function (firstNode, secondNode, current) {
404-
var firstNodeInLeft = this._existsInSubtree(firstNode, current._left),
405-
secondNodeInLeft = this._existsInSubtree(secondNode, current._left),
406-
firstNodeInRight = this._existsInSubtree(firstNode, current._right),
407-
secondNodeInRight = this._existsInSubtree(secondNode, current._right);
404+
var firstNodeInLeft = this._existsInSubtree(firstNode, current._left);
405+
var secondNodeInLeft = this._existsInSubtree(secondNode, current._left);
406+
var firstNodeInRight = this._existsInSubtree(firstNode, current._right);
407+
var secondNodeInRight = this._existsInSubtree(secondNode, current._right);
408408
if ((firstNodeInLeft && secondNodeInRight) ||
409409
(firstNodeInRight && secondNodeInLeft)) {
410410
return current;

src/data-structures/heap.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
* @param {Number} index The parent.
7272
*/
7373
exports.Heap.prototype._heapify = function (index) {
74-
var extr = index,
75-
left = 2 * index + 1,
76-
right = 2 * index + 2,
77-
temp;
74+
var extr = index;
75+
var left = 2 * index + 1;
76+
var right = 2 * index + 2;
77+
var temp;
7878

7979
if (left < this._heap.length &&
8080
this._cmp(this._heap[left], this._heap[index]) > 0) {
@@ -105,9 +105,9 @@
105105
*/
106106
exports.Heap.prototype.changeKey = function (index, value) {
107107
this._heap[index] = value;
108-
var elem = this._heap[index],
109-
parent = Math.floor(index / 2),
110-
temp;
108+
var elem = this._heap[index];
109+
var parent = Math.floor(index / 2);
110+
var temp;
111111
if (elem !== undefined) {
112112
while (parent >= 0 && this._cmp(elem, this._heap[parent]) > 0) {
113113
temp = this._heap[parent];

src/data-structures/interval-tree.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@
125125
if (node.interval[0] <= point && node.interval[1] >= point) {
126126
return true;
127127
}
128-
var result = false, temp;
128+
var result = false;
129+
var temp;
129130
['left', 'right'].forEach(function (key) {
130131
temp = node[key];
131132
if (temp) {
@@ -157,7 +158,8 @@
157158
if (intersects(node.interval, interval)) {
158159
return true;
159160
}
160-
var result = false, temp;
161+
var result = false;
162+
var temp;
161163
['left', 'right'].forEach(function (side) {
162164
temp = node[side];
163165
if (temp && temp.max >= interval[0]) {
@@ -212,8 +214,10 @@
212214
* @return {Node} Node with the largest endpoint.
213215
*/
214216
exports.IntervalTree.prototype.findMax = function (node) {
215-
var stack = [node],
216-
current, max = -Infinity, maxNode;
217+
var stack = [node];
218+
var current;
219+
var max = -Infinity;
220+
var maxNode;
217221
while (stack.length) {
218222
current = stack.pop();
219223
if (current.left) {
@@ -275,8 +279,8 @@
275279
// Adjust the max value
276280
var p = node.parentNode;
277281
if (p) {
278-
var maxNode = this.findMax(p),
279-
max = maxNode.interval[1];
282+
var maxNode = this.findMax(p);
283+
var max = maxNode.interval[1];
280284
while (maxNode) {
281285
if (maxNode.max === node.interval[1]) {
282286
maxNode.max = max;

src/data-structures/linked-list.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@
138138
if (this.first === null) {
139139
return false;
140140
}
141-
var temp = this.first,
142-
next, prev;
141+
var temp = this.first;
142+
var next;
143+
var prev;
143144
while (temp) {
144145
if (temp.data === data) {
145146
next = temp.next;
@@ -171,8 +172,8 @@
171172
* @return {Boolean} Returns true if linked list contains cycle.
172173
*/
173174
exports.LinkedList.prototype.hasCycle = function () {
174-
var fast = this.first,
175-
slow = this.first;
175+
var fast = this.first;
176+
var slow = this.first;
176177
while (true) {
177178
if (fast === null) {
178179
return false;
@@ -245,9 +246,9 @@
245246
if (!this.first || !this.first.next) {
246247
return;
247248
}
248-
var current = this.first.next,
249-
prev = this.first,
250-
temp;
249+
var current = this.first.next;
250+
var prev = this.first;
251+
var temp;
251252
while (current) {
252253
temp = current.next;
253254
current.next = prev;

src/data-structures/suffix-tree.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
// Find the maximum prefix and split the current node if prefix exists
4242
var prefix = maxPrefix(current.value, suffix);
4343
if (prefix.length) {
44-
var temp = current.value,
45-
suffixSuffix = suffix.substr(prefix.length, suffix.length),
46-
currentSuffix = temp.substr(prefix.length, temp.length);
44+
var temp = current.value;
45+
var suffixSuffix = suffix.substr(prefix.length, suffix.length);
46+
var currentSuffix = temp.substr(prefix.length, temp.length);
4747
current.value = prefix;
4848
addNode(currentSuffix, current);
4949
addNode(suffixSuffix, current);

src/graphics/bresenham-line-drawing.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
*/
1212
function drawLine(x1, y1, x2, y2, draw) {
1313
drawPoint = draw || drawPoint;
14-
var dx = Math.abs(x2 - x1),
15-
dy = Math.abs(y2 - y1),
16-
cx = (x1 < x2) ? 1 : -1,
17-
cy = (y1 < y2) ? 1 : -1,
18-
error = dx - dy,
19-
doubledError;
14+
var dx = Math.abs(x2 - x1);
15+
var dy = Math.abs(y2 - y1);
16+
var cx = (x1 < x2) ? 1 : -1;
17+
var cy = (y1 < y2) ? 1 : -1;
18+
var error = dx - dy;
19+
var doubledError;
2020

2121
while (x1 !== x2 || y1 !== y2) {
2222
drawPoint(x1, y1);

src/graphs/others/topological-sort.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
* var vertices = topsort(graph); // ['v3', 'v4', 'v1', 'v5', 'v2']
4444
*/
4545
return function (graph) {
46-
var result = [],
47-
visited = [],
48-
temp = [];
46+
var result = [];
47+
var visited = [];
48+
var temp = [];
4949
for (var node in graph) {
5050
if (!visited[node] && !temp[node]) {
5151
topologicalSortHelper(node, visited, temp, graph, result);

0 commit comments

Comments
 (0)
X Tutup