sectioning 提供了针对数组和切片的功能
Index
查找符合条件元素在数组中的位置Delete
删除符合条件的切片元素Unique
提取数组中的唯一元素Count
统计数组或切片中包含指定什的数量Cut
Cut 去除 slice 中符合 eq 的元素Each
遍历 slice,并对每个元素执行 fnFilter
遍历 slice,并对每个元素执行 fn,返回符合 fn 的元素First
返回 slice 中第一个元素IsEmpty
判断 slice 是否为空Pop
删除 slice 中的最后一个元素,并返回该元素Push
在 slice 的末尾添加元素Shuffle
打乱 sliceSort
排序 sliceMinOrMax
返回 slice 中最小或者最大的元素
GO 从 0.8.0 开始采用泛型技术,仅支持 go1.18 以上版本
func TestShuffle(t *testing.T) {
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
b := Shuffle(intSlice)
t.Log(b)
c := Shuffle(objSlice)
t.Log(c)
}
func TestSort(t *testing.T) {
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
b := Sort(intSlice, func(i, j int) bool {
return i > j
})
t.Log(b)
c := Sort(objSlice, func(i, j *obj) bool {
return i.ID > j.ID
})
t.Log(c)
}