[+] Allow reversed ranges
This commit is contained in:
+4
-1
@@ -15,5 +15,8 @@ export function range(fromOrTo: number, to?: number, step = 1): number[]
|
|||||||
const from = to ? fromOrTo : 0
|
const from = to ? fromOrTo : 0
|
||||||
to = to ? to : fromOrTo
|
to = to ? to : fromOrTo
|
||||||
|
|
||||||
return [...Array(Math.floor((to - from) / step))].map((_, i) => from + i * step);
|
if (to == from) return []
|
||||||
|
const mul = to > from ? 1 : -1
|
||||||
|
|
||||||
|
return [...Array(Math.floor((Math.abs(to - from)) / step))].map((_, i) => from + i * step * mul);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user