mirror of
https://github.com/rjNemo/underscore
synced 2026-06-06 10:36:43 +00:00
16 lines
357 B
Go
16 lines
357 B
Go
package underscore
|
|
|
|
// Range creates a sequence of numbers, i.e. u.Range(0, 3) = [0 1 2 3], while u.Range(3, 0) = [3 2 1 0]
|
|
func Range(start int, end int) (result []int) {
|
|
if start < end {
|
|
for i := start; i <= end; i++ {
|
|
result = append(result, i)
|
|
}
|
|
} else {
|
|
for i := start; i >= end; i-- {
|
|
result = append(result, i)
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|