Skip to content

Commit c660898

Browse files
committed
Bump version to 0.1.0 and fix linting errors
1 parent c8c77c2 commit c660898

File tree

8 files changed

+71
-67
lines changed

8 files changed

+71
-67
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all: jshint test coverage
1+
all: jshint coverage
22

33
setup:
44
npm install

algorithms/graph/dijkstra.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ function dijkstra(graph, s) {
4747
var currNode;
4848
while (!q.isEmpty()) {
4949
currNode = q.extract();
50-
graph.neighbors(currNode).forEach(function (v) {
50+
var neighbors = graph.neighbors(currNode);
51+
for (var i = 0; i < neighbors.length; i++) {
52+
var v = neighbors[i];
5153
// relaxation
5254
var newDistance = distance[currNode] + graph.edge(currNode, v);
5355
if (newDistance < distance[v]) {
5456
distance[v] = newDistance;
5557
previous[v] = currNode;
5658
q.changePriority(v, distance[v]);
5759
}
58-
});
60+
}
5961
}
6062
return {
6163
distance: distance,

algorithms/math/gcd.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ var gcdBinaryIterative = function (a, b) {
6565
return a;
6666
}
6767

68-
// Let shift = log(K), where K is the greatest power of 2 dividing both a and b
69-
for (var shift = 0; ((a | b) & 1) == 0; ++shift) {
68+
// Let shift = log(K), where K is the greatest power of 2
69+
// dividing both a and b
70+
for (var shift = 0; ((a | b) & 1) === 0; ++shift) {
7071
a >>= 1;
7172
b >>= 1;
7273
}

package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
{
22
"name": "algorithms",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Traditional computer science algorithms and data structures implemented in JavaScript",
55
"directories": {
66
"test": "test"
77
},
88
"main": "main.js",
99
"dependencies": {},
1010
"devDependencies": {
11-
"coveralls": "*",
12-
"istanbul": "*",
13-
"mocha": "*"
11+
"coveralls": "^2.10.0",
12+
"istanbul": "^0.2.10",
13+
"jshint": "^2.5.1",
14+
"mocha": "^1.20.0"
1415
},
1516
"repository": {
1617
"type": "git",
1718
"url": "https://github.com/felipernb/algorithms.js"
1819
},
19-
"scripts": {
20-
"test": "mocha -R spec --recursive test",
21-
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- -R spec --recursive test",
22-
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
23-
},
2420
"keywords": [
2521
"computer science",
2622
"cs",

test/algorithms/math/gcd.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,21 @@ describe('GCD', function () {
3838
assert.equal(gcd(35, 49), 7);
3939
});
4040

41-
it('should calculate the correct GCD between two numbers using the binary method', function () {
42-
var gcdb = gcd.binary;
43-
assert.equal(gcdb(1, 0), 1);
44-
assert.equal(gcdb(2, 2), 2);
45-
assert.equal(gcdb(2, 4), 2);
46-
assert.equal(gcdb(4, 2), 2);
47-
assert.equal(gcdb(5, 2), 1);
48-
assert.equal(gcdb(10, 100), 10);
49-
assert.equal(gcdb(10000000, 2), 2);
50-
assert.equal(gcdb(7, 49), 7);
51-
assert.equal(gcdb(7, 5), 1);
52-
assert.equal(gcdb(35, 49), 7);
41+
it('should calculate the correct GCD between two numbers using ' +
42+
'the binary method', function () {
43+
var gcdb = gcd.binary;
44+
assert.equal(gcdb(1, 0), 1);
45+
assert.equal(gcdb(0, 1), 1);
46+
assert.equal(gcdb(0, 0), 0);
47+
assert.equal(gcdb(2, 2), 2);
48+
assert.equal(gcdb(2, 4), 2);
49+
assert.equal(gcdb(4, 2), 2);
50+
assert.equal(gcdb(5, 2), 1);
51+
assert.equal(gcdb(10, 100), 10);
52+
assert.equal(gcdb(10000000, 2), 2);
53+
assert.equal(gcdb(7, 49), 7);
54+
assert.equal(gcdb(7, 5), 1);
55+
assert.equal(gcdb(35, 49), 7);
5356
});
5457
});
5558

test/data_structures/priority_queue.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,23 @@ describe('Min Priority Queue', function () {
5656
assert(q.isEmpty());
5757
});
5858

59-
it('can receive a dictionary with item => priority in construction', function () {
60-
var q = new PriorityQueue({
61-
a: 10,
62-
b: 2091,
63-
c: 4,
64-
d: 1,
65-
e: 5
66-
});
59+
it('can receive a dictionary with item => priority in construction',
60+
function () {
61+
var q = new PriorityQueue({
62+
a: 10,
63+
b: 2091,
64+
c: 4,
65+
d: 1,
66+
e: 5
67+
});
6768

68-
assert(!q.isEmpty());
69-
assert.equal(q.extract(), 'd');
70-
assert.equal(q.extract(), 'c');
71-
assert.equal(q.extract(), 'e');
72-
assert.equal(q.extract(), 'a');
73-
assert.equal(q.extract(), 'b');
74-
});
69+
assert(!q.isEmpty());
70+
assert.equal(q.extract(), 'd');
71+
assert.equal(q.extract(), 'c');
72+
assert.equal(q.extract(), 'e');
73+
assert.equal(q.extract(), 'a');
74+
assert.equal(q.extract(), 'b');
75+
});
7576

7677
it('should be possible to change the priority of an item', function () {
7778
var q = new PriorityQueue({

test/util/comparator.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (C) 2014 Felipe Ribeiro
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
5-
* of this software and associated documentation files (the "Software"), to
5+
* of this software and associated documentation files (the 'Software'), to
66
* deal in the Software without restriction, including without limitation the
77
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
88
* sell copies of the Software, and to permit persons to whom the Software is
@@ -11,7 +11,7 @@
1111
* The above copyright notice and this permission notice shall be included in
1212
* all copies or substantial portions of the Software.
1313
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1515
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1616
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1717
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
@@ -25,28 +25,29 @@ var Comparator = require('../../util/comparator'),
2525
assert = require('assert');
2626

2727
describe('Comparator', function () {
28-
it("Should use a default arithmetic comparison if no function is passed", function () {
29-
var c = new Comparator();
30-
assert.equal(c.compare(1, 1), 0);
31-
assert.equal(c.compare(1, 2), -1);
32-
assert.equal(c.compare(1, 0), 1);
33-
assert.equal(c.compare('a', 'b'), -1);
34-
assert(c.lessThan(0, 1));
35-
assert(!c.lessThan(1, 1));
36-
assert(c.lessThanOrEqual(1, 1));
37-
assert(c.lessThanOrEqual(0, 1));
38-
assert(!c.lessThanOrEqual(1, 0));
39-
assert(c.greaterThan(1, 0));
40-
assert(!c.greaterThan(1, 1));
41-
assert(c.greaterThanOrEqual(1, 1));
42-
assert(c.greaterThanOrEqual(1, 0));
43-
assert(!c.greaterThanOrEqual(0, 1));
44-
assert(c.equal(0, 0));
45-
assert(!c.equal(0, 1));
46-
});
28+
it('Should use a default arithmetic comparison if no function is passed',
29+
function () {
30+
var c = new Comparator();
31+
assert.equal(c.compare(1, 1), 0);
32+
assert.equal(c.compare(1, 2), -1);
33+
assert.equal(c.compare(1, 0), 1);
34+
assert.equal(c.compare('a', 'b'), -1);
35+
assert(c.lessThan(0, 1));
36+
assert(!c.lessThan(1, 1));
37+
assert(c.lessThanOrEqual(1, 1));
38+
assert(c.lessThanOrEqual(0, 1));
39+
assert(!c.lessThanOrEqual(1, 0));
40+
assert(c.greaterThan(1, 0));
41+
assert(!c.greaterThan(1, 1));
42+
assert(c.greaterThanOrEqual(1, 1));
43+
assert(c.greaterThanOrEqual(1, 0));
44+
assert(!c.greaterThanOrEqual(0, 1));
45+
assert(c.equal(0, 0));
46+
assert(!c.equal(0, 1));
47+
});
4748

48-
it("should allow comparison function to be defined by user", function () {
49-
var compareFn = function (a, b) {
49+
it('should allow comparison function to be defined by user', function () {
50+
var compareFn = function () {
5051
return 0;
5152
};
5253
var c = new Comparator(compareFn);
@@ -68,7 +69,7 @@ describe('Comparator', function () {
6869
assert(c.equal(0, 1));
6970
});
7071

71-
it("Should allow reversing the comparisons", function () {
72+
it('Should allow reversing the comparisons', function () {
7273
var c = new Comparator();
7374
c.reverse();
7475
assert.equal(c.compare(1, 1), 0);

util/comparator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Comparator.prototype.greaterThanOrEqual = function (a, b) {
6060
};
6161

6262
Comparator.prototype.equal = function (a, b) {
63-
return this.compare(a, b) == 0;
63+
return this.compare(a, b) === 0;
6464
};
6565

6666
/**
@@ -74,6 +74,6 @@ Comparator.prototype.reverse = function () {
7474
this.compare = function (a, b) {
7575
return originalCompareFn(b, a);
7676
};
77-
}
77+
};
7878

7979
module.exports = Comparator;

0 commit comments

Comments
 (0)