-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathlogic.go
More file actions
46 lines (39 loc) · 686 Bytes
/
logic.go
File metadata and controls
46 lines (39 loc) · 686 Bytes
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
package Answer
import (
"sort"
)
//Answers 类型
type Answers struct {
content string
sum int32
freq int32
}
//AnswersList 类型
type AnswersList []*Answers
func (l AnswersList) Len() int {
return len(l)
}
func (l AnswersList) Less(i, j int) bool {
if l[i].freq < l[j].freq {
return true
} else if l[i].freq > l[j].freq {
return false
} else {
return l[i].sum < l[j].sum
}
}
func (l AnswersList) Swap(i, j int) {
temp := l[i]
l[i] = l[j]
l[j] = temp
}
func processLogic(input []*Answers, flag bool) (result string) {
p := AnswersList(input)
sort.Sort(p)
if flag {
result = p[0].content
} else {
result = p[len(p)-1].content
}
return result
}