1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 16:52:29 +08:00

feat: add func ContainSubSlice

This commit is contained in:
dudaodong
2022-01-13 11:52:21 +08:00
6 changed files with 57 additions and 5 deletions

View File

@@ -24,6 +24,21 @@ func Contain[T comparable](slice []T, value T) bool {
return false
}
// ContainSubSlice check if the slice contain subslice or not
func ContainSubSlice[T comparable](slice, subslice []T) bool {
unique := make(map[T]bool)
for _, v := range slice {
unique[v] = true
}
for _, v := range subslice {
if !unique[v] {
return false
}
}
return true
}
// Chunk creates an slice of elements split into groups the length of size.
func Chunk[T any](slice []T, size int) [][]T {
var res [][]T