mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-19 10:54:46 +08:00
优化代码规范
This commit is contained in:
@@ -39,12 +39,13 @@ func RandN[E ~[]T, T any](arr E, num int) []T {
|
||||
}
|
||||
Shuffle(index)
|
||||
if len(index) > num {
|
||||
index = index
|
||||
index = index[:num]
|
||||
}
|
||||
ret := make([]T, 0, len(index))
|
||||
for i := range index {
|
||||
ret = append(ret, arr[index[i]])
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -104,4 +105,4 @@ func GetPointerFunc[E ~[]T, T any](arr E, f func(T) bool) *T {
|
||||
}
|
||||
|
||||
return &arr[index]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user