feat: add Range function

This commit is contained in:
dudaodong committed 2023-03-06 17:49:56 +08:00
1 parent 6a9eb645bb
commit 28d0428b50
3 files changed
+49

No files matched your search

+17
View File
@@ -183,3 +183,20 @@ func Average[T constraints.Integer | constraints.Float](numbers ...T) T {
}
return sum / n
}
// Range creates a slice of numbers from start with specified count, element step is 1.
// Play: todo
func Range[T constraints.Integer | constraints.Float](start T, count int) []T {
size := count
if count < 0 {
size = -count
}
result := make([]T, size)
for i, j := 0, start; i < size; i, j = i+1, j+1 {
result[i] = j
}
return result
}