-
Notifications
You must be signed in to change notification settings - Fork 0
/
Leaderboard.gs
48 lines (36 loc) · 975 Bytes
/
Leaderboard.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const LeaderboardType = {
MOST_USED: 0,
LEAST_USED: 1
};
function getSortedEmojis(sheet, leaderboardLength, leaderboardType) {
let values = sheet.getDataRange().getValues();
if (leaderboardLength > values.length) {
leaderboardLength = values.length;
}
if (leaderboardType == LeaderboardType.MOST_USED) {
values.sort(compareSheetRecords).reverse();
} else {
values.sort(compareSheetRecords);
}
let leaderboard = [];
for (let i = 0; i < leaderboardLength; i++) {
leaderboard[i] = values[i];
}
return leaderboard;
}
function compareSheetRecords(a, b) {
let reactionsCountA = a[1];
let reactionsCountB = b[1];
if (reactionsCountA != reactionsCountB) {
return reactionsCountA - reactionsCountB;
}
let emojiNameA = a[0];
let emojiNameB = b[0];
if (emojiNameA < emojiNameB) {
return -1;
}
if (emojiNameA > emojiNameB) {
return 1;
}
return 0;
}