你好,
在今天的文章中,我将谈论https://github.com/hisyntax/sort,这是我用于排序数据的GO库。
什么是sort?
sort是一个go库,对数据(字符串和int)的出现数量进行分类,并以降序返回所需的数据长度,而无需重复。
用例范围为:
- 在电子商务平台中实现趋势功能
- 获得有序(购买的)产品E.T.C
此库在X软件包中包含两个方法:
出去()
sortint()将一个int的数组分为
package main
import (
"fmt"
sorter "github.com/hisyntax/sort/x"
)
func main() {
arr := []int{2, 3, 10, 4, 1, 10, 1, 4, 4, 5, 6, 6, 6, 6, 1, 6, 7, 8, 12, 9, 1, 1, 1}
//pass in the array to be sorted and the desired length of data to be returned in descending order
//the lenght should be zero(0) if you want to get all the sorted data
sortedInt := sorter.SortInt(arr, 3)
fmt.Printf("This is the sorted int data: %v\n", sortedInt)
}
sortstring()
sortstring()将字符串数组
排列
package main
import (
"fmt"
sorter "github.com/hisyntax/sort/x"
)
func main() {
arr := []string{"by", "me", "come", "by", "me", "hello", "hey", "hey", "me", "buy", "by", "come", "hello", "go"}
//pass in the array to be sorted and the desired length of data to be returned in descending order
//the lenght should be zero(0) if you want to get all the sorted data
sortedString := sorter.SortString(arr, 3)
fmt.Printf("This is the sorted string data: %v\n", sortedString)
}