File tree 4 files changed +22
-20
lines changed
algorithms/selection-sort
4 files changed +22
-20
lines changed Original file line number Diff line number Diff line change 1
1
const { StdOut } = require ( '../../libs' )
2
-
3
- /**
4
- * A default comparing function that
5
- * returns -1 when `a` is less than `b`,
6
- * returns 1 when `a` is greater than `b` or
7
- * returns 0 when `a` is equal to `b`.
8
- * @param {* } a Comparable object `a`
9
- * @param {* } b Comparable object `b`
10
- */
11
- const defaultComparator = ( a , b ) => {
12
- if ( a === b ) return 0
13
-
14
- return a < b ? - 1 : 1
15
- }
2
+ const { defaultComparator } = require ( '../../common' )
16
3
17
4
/**
18
5
* Selection
Original file line number Diff line number Diff line change 1
1
const Selection = require ( './selection-sort' )
2
2
const { newArrayOf } = require ( '../../utils' )
3
3
const { StdRandom } = require ( '../../libs' )
4
-
5
- const comparator = ( a , b ) => {
6
- if ( a < b ) return - 1
7
- else if ( a > b ) return 1
8
- return 0
9
- }
4
+ const { defaultComparator : comparator } = require ( '../../common' )
10
5
11
6
describe ( 'Unit Tests: Selection Sort Algorithm' , ( ) => {
12
7
beforeEach ( ( ) => {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * A default comparing function that
3
+ * returns -1 when `a` is less than `b`,
4
+ * returns 1 when `a` is greater than `b` or
5
+ * returns 0 when `a` is equal to `b`.
6
+ * @param {* } a Comparable object `a`
7
+ * @param {* } b Comparable object `b`
8
+ */
9
+ const defaultComparator = ( a , b ) => {
10
+ if ( a === b ) return 0
11
+
12
+ return a < b ? - 1 : 1
13
+ }
14
+
15
+ module . exports = {
16
+ defaultComparator
17
+ }
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ ...require ( './comparators.common' )
3
+ }
You can’t perform that action at this time.
0 commit comments