fix: 修复空提交问题
This commit is contained in:
@@ -8,3 +8,12 @@ func FindWithIndex[T any](slice []T, predicate func(item T) bool) (int, *T, bool
|
||||
}
|
||||
return -1, nil, false
|
||||
}
|
||||
func LastFourElements[T any](s []T, n1 int) []T {
|
||||
n := len(s)
|
||||
if n <= n1 {
|
||||
// 切片长度小于等于4时,返回整个切片
|
||||
return s
|
||||
}
|
||||
// 切片长度大于4时,返回最后4个元素(从n-4索引到末尾)
|
||||
return s[n-n1:]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user