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

Commit 1ecb5b4

Browse files
committed
Add comparator annotations.
1 parent f7ebddc commit 1ecb5b4

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

‎src/utils/comparator/Comparator.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
export default class Comparator {
22
/**
3-
* @param {function(a: *, b: *)} [compareFunction]
3+
* @param {function(a: *, b: *)} [compareFunction] - It may be custom compare function that, let's
4+
* say may compare custom objects together.
45
*/
56
constructor(compareFunction) {
67
this.compare = compareFunction || Comparator.defaultCompareFunction;
78
}
89

910
/**
11+
* Default comparison function. It just assumes that "a" and "b" are strings or numbers.
1012
* @param {(string|number)} a
1113
* @param {(string|number)} b
1214
* @returns {number}
@@ -19,26 +21,59 @@ export default class Comparator {
1921
return a < b ? -1 : 1;
2022
}
2123

24+
/**
25+
* Checks if two variables are equal.
26+
* @param {*} a
27+
* @param {*} b
28+
* @return {boolean}
29+
*/
2230
equal(a, b) {
2331
return this.compare(a, b) === 0;
2432
}
2533

34+
/**
35+
* Checks if variable "a" is less than "b".
36+
* @param {*} a
37+
* @param {*} b
38+
* @return {boolean}
39+
*/
2640
lessThan(a, b) {
2741
return this.compare(a, b) < 0;
2842
}
2943

44+
/**
45+
* Checks if variable "a" is greater than "b".
46+
* @param {*} a
47+
* @param {*} b
48+
* @return {boolean}
49+
*/
3050
greaterThan(a, b) {
3151
return this.compare(a, b) > 0;
3252
}
3353

54+
/**
55+
* Checks if variable "a" is less than or equal to "b".
56+
* @param {*} a
57+
* @param {*} b
58+
* @return {boolean}
59+
*/
3460
lessThanOrEqual(a, b) {
3561
return this.lessThan(a, b) || this.equal(a, b);
3662
}
3763

64+
/**
65+
* Checks if variable "a" is greater than or equal to "b".
66+
* @param {*} a
67+
* @param {*} b
68+
* @return {boolean}
69+
*/
3870
greaterThanOrEqual(a, b) {
3971
return this.greaterThan(a, b) || this.equal(a, b);
4072
}
4173

74+
/**
75+
* Reverses the comparison order.
76+
*/
4277
reverse() {
4378
const compareOriginal = this.compare;
4479
this.compare = (a, b) => compareOriginal(b, a);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /