[+] Allow reversed ranges

This commit is contained in:
Hykilpikonna
2021-12-11 00:16:59 -05:00
parent 167e08878d
commit b44e7db4c5
+4 -1
View File
@@ -15,5 +15,8 @@ export function range(fromOrTo: number, to?: number, step = 1): number[]
const from = to ? fromOrTo : 0
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);
}