No Description

range.js 638B

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