range.js 531 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * 序号列表生成函数
  3. *
  4. * @param {Number} start 起始值
  5. * @param {Number} stop 结束值
  6. * @param {Number} step 自增值
  7. * @return {Object}
  8. */
  9. function range (start, stop, step) {
  10. var index, len
  11. var result = []
  12. var args = arguments
  13. if (args.length < 2) {
  14. stop = args[0]
  15. start = 0
  16. }
  17. index = start >> 0
  18. len = stop >> 0
  19. if (index < stop) {
  20. step = step >> 0 || 1
  21. for (; index < len; index += step) {
  22. result.push(index)
  23. }
  24. }
  25. return result
  26. }
  27. module.exports = range