_sequence.js 384 B

123456789101112131415161718
  1. define(function () {
  2. function sequence(iteratee, start, stop, step) {
  3. if (stop == null) {
  4. stop = start || 0;
  5. start = 0;
  6. }
  7. if (!step) {
  8. step = stop < start ? -1 : 1;
  9. }
  10. var rest = (stop - start) % step;
  11. stop += (rest && step - rest);
  12. for ( ; start != stop ; start += step) if (iteratee(start)) return start;
  13. }
  14. return sequence;
  15. });