liudong
2023-05-29 340f156319b863525e50e900c58e59b86ecb3d5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Generate an integer Array containing an arithmetic progression. A port of
// the native Python `range()` function. See
// [the Python documentation](https://docs.python.org/library/functions.html#range).
function range(start, stop, step) {
  if (stop == null) {
    stop = start || 0;
    start = 0;
  }
  if (!step) {
    step = stop < start ? -1 : 1;
  }
 
  var length = Math.max(Math.ceil((stop - start) / step), 0);
  var range = Array(length);
 
  for (var idx = 0; idx < length; idx++, start += step) {
    range[idx] = start;
  }
 
  return range;
}
 
module.exports = range;