-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.go
42 lines (34 loc) · 977 Bytes
/
sort.go
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
package main
import "sort"
// Extract is a function that converts a multiple stat into a single stat
type Extract func(st Stat) int
// ExtractCommits extract the commit section of the given stat
var ExtractCommits = func(st Stat) int {
return st.Commits
}
// ExtractAdditions extract the adds section of the given stat
var ExtractAdditions = func(st Stat) int {
return st.Additions
}
// ExtractDeletions extract the rms section of the given stat
var ExtractDeletions = func(st Stat) int {
return st.Deletions
}
// Reviews extract the reviewed prs section of the given stat
var Reviews = func(st Stat) int {
return st.Reviews
}
func Sort(s Stats, extract Extract) []StatPair {
var result []StatPair
for key, value := range s.data {
result = append(result, StatPair{Key: key, Value: extract(value)})
}
sort.Slice(result, func(i int, j int) bool {
return result[i].Value > result[j].Value
})
return result
}
type StatPair struct {
Key string
Value int
}