This funtion could be used in cicles and make it more clear:
for (const i of range(1, 10)) {
console.log(i)
}
Outputs numbers from 1 to 9.
for (const i of range(10, 1)) {
console.log(i)
}
Outputs numbers from 9 to 1.
The logic of the range is based on array behavior and created to create indexes.
const arr = ['a', 'b', 'c']
for (const i of range(0, arr.length)) {
console.log(arr[i])
}
for (const i of range(arr.length, i)) {
console.log(arr[i])
}
Output order: a b c b c a