range.js 520 B

123456789101112131415161718192021222324252627
  1. var countSteps = require('../math/countSteps');
  2. /**
  3. * Returns an Array of numbers inside range.
  4. */
  5. function range(start, stop, step) {
  6. if (stop == null) {
  7. stop = start;
  8. start = 0;
  9. }
  10. step = step || 1;
  11. var result = [],
  12. nSteps = countSteps(stop - start, step),
  13. i = start;
  14. while (i <= stop) {
  15. result.push(i);
  16. i += step;
  17. }
  18. return result;
  19. }
  20. module.exports = range;