Skip to content

Commit 0140cc7

Browse files
committed
[REFACTOR] [Hacker Rank] Interview Preparation Kit: Sorting: Comparator.
* Adjusted the interface to match what hackerrank expects.
1 parent 6e7efa2 commit 0140cc7

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.Player.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Start Given code
22

3-
export class Player {
3+
class Player {
44
name = '';
55

66
score = 0;
@@ -18,3 +18,4 @@ export class Player {
1818
// End Given code
1919

2020
export default { Player };
21+
export { Player };

src/hackerrank/interview_preparation_kit/sort/ctci_comparator_sorting.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { Player } from './ctci_comparator_sorting.Player.js';
66

7-
export class SortablePlayer extends Player {
7+
class SortablePlayer extends Player {
88
name = '';
99

1010
score = 0;
@@ -34,14 +34,20 @@ export class SortablePlayer extends Player {
3434
}
3535
}
3636

37-
export function comparatorSorting(players) {
37+
function comparatorSorting(players) {
3838
const sortedPlayers = [...players].sort((a, b) => a.comparator(b));
3939

4040
return sortedPlayers.map((player) => player.toString());
4141
}
4242

43-
export function comparatorSortingPrint(players) {
43+
function comparatorSortingPrint(players) {
4444
console.log(comparatorSorting(players)?.join('\n'));
4545
}
4646

47-
export default { Player, SortablePlayer, comparatorSorting };
47+
export default {
48+
Player,
49+
SortablePlayer,
50+
comparatorSorting,
51+
comparatorSortingPrint
52+
};
53+
export { Player, SortablePlayer, comparatorSorting, comparatorSortingPrint };

0 commit comments

Comments
 (0)