Skip to content

Commit 5ec5a9b

Browse files
committed
JsLint
1 parent e2abe6b commit 5ec5a9b

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/others/minkowski-distance.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
function chebyshevDistance (x, y, lx, p, mathfn) {
77
var ret = -p;
88
var i;
9-
10-
for (i = 0; i < lx; i++) {
9+
10+
for (i = 0; i < lx; i += 1) {
1111
ret = mathfn(ret, Math.abs(x[i] - y[i]));
12-
}
12+
}
1313

1414
return ret;
1515
}
@@ -28,32 +28,28 @@
2828

2929
if (p === Number.POSITIVE_INFINITY) {
3030
return chebyshevDistance(x, y, lx, p, Math.max);
31-
}
32-
else if (p === Number.NEGATIVE_INFINITY) {
31+
} else if (p === Number.NEGATIVE_INFINITY) {
3332
return chebyshevDistance(x, y, lx, p, Math.min);
34-
}
35-
else if (p < 1) {
33+
} else if (p < 1) {
3634
throw 'p less than 1 will violate triangle inequality';
37-
}
38-
else {
35+
} else {
3936
d = 0;
4037

41-
for (i = 0; i < lx; i++) {
38+
for (i = 0; i < lx; i += 1) {
4239
d += Math.pow(Math.abs(x[i] - y[i]), p);
4340
}
4441

4542
return isNaN(d)
4643
? 0
47-
: Math.pow(d, 1/p);
44+
: Math.pow(d, 1 / p);
45+
4846
}
4947

5048
}
5149

52-
5350
/**
54-
* The Minkowski distance between two points gets generalized
51+
* The Minkowski distance between two points gets generalized
5552
* metric distance
56-
*
5753
* when p === 1, this becomes same as Manhattan Distance
5854
* when p === 2, this becomes same as Euclidean Distance
5955
* when p === Positive or Negative Infinity,
@@ -66,7 +62,7 @@
6662
* var dist = require('path-to-algorithms/src/others/' +
6763
* 'minkowski-distance').minkowskiDistance;
6864
* console.log(dist([0, 1], [1, 1], 2)); // 1
69-
*
65+
*
7066
* @param {Array} x source point
7167
* @param {Array} y target point
7268
* @param {Number} p order of Minkowski distance
@@ -75,10 +71,9 @@
7571
*/
7672
return function (x, y, p) {
7773
return minkowskiDistance (x, x.length, y, y.length, p);
78-
}
74+
};
7975
}());
8076

81-
8277
exports.minkowskiDistance = minkowskiDistance;
8378

84-
}(typeof exports === 'undefined' ? window : exports));
79+
}(typeof exports === 'undefined' ? window : exports));

test/others/minkowski-distance.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ describe('Minkowski Distance', function () {
2020
expect(minkowskiDistance([0, 1, 4], [1, 1, 6], Number.NEGATIVE_INFINITY)).toBe(0);
2121
});
2222
it('should throw when 2 points are not in equal length', function () {
23-
expect( function () {
23+
expect(function () {
2424
minkowskiDistance([1, 2], [1], 1)
2525
}).toThrow('2 points must have same array length');
2626
});
2727
it('should throw when p is not defined', function () {
28-
expect( function () {
28+
expect(function () {
2929
minkowskiDistance([1, 2], [1, 2])
3030
}).toThrow('p must be a number');
3131
});
3232
it('should throw when p is not a number', function () {
33-
expect( function () {
33+
expect(function () {
3434
minkowskiDistance([1, 2], [1, 2], NaN)
3535
}).toThrow('p must be a number');
3636
});
3737
it('should throw when p is less than 1', function () {
38-
expect( function () {
38+
expect(function () {
3939
minkowskiDistance([1, 2], [1, 2], 0)
4040
}).toThrow('p less than 1 will violate triangle inequality');
4141
});

0 commit comments

Comments
 (0)