We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 19ca701 commit e9caed5Copy full SHA for e9caed5
sorted.go
@@ -5,26 +5,10 @@ import (
5
"sort"
6
)
7
8
-type i18nStruct struct {
9
- lang string
10
- arr []string
11
-}
12
-
13
-func (i18n i18nStruct) Less(i, j int) bool {
14
- less := collate.IndexString(i18n.lang)
15
- return less(i18n.arr[i], i18n.arr[j])
16
17
18
-func (i18n i18nStruct) Len() int {
19
- return len(i18n.arr)
20
21
22
-func (i18n i18nStruct) Swap(i, j int) {
23
- i18n.arr[i], i18n.arr[j] = i18n.arr[j], i18n.arr[i]
24
25
26
func sorted(arr []string, lang string) []string {
27
- i18n := i18nStruct{lang, arr}
28
- sort.Sort(i18n)
29
- return i18n.arr
+ less := collate.IndexString(lang)
+ sort.SliceStable(arr, func(i, j int) bool {
+ return less(arr[i], arr[j])
+ })
+ return arr
30
}
0 commit comments