Nodejs Number Iterate upto(up, iterator)

Here you can find the source of upto(up, iterator)

Method Source Code

Number.prototype.upto = function (up, iterator) {
  for (var i = this.valueOf(); i <= up; i++) {
    iterator(i);/*w  w  w  . j av a  2s .  co  m*/
  }
  return this.valueOf();
};

Related

  1. __iterator__(iterKeys)
    "use strict";
    Number.prototype.__iterator__ = function (iterKeys) {
      if (this % 1) {
        throw new TypeError("Integer expected for number iterator");
      var i = 1 - iterKeys,
          j = this + i;
      if (j < 0) {
        i = j - i + iterKeys;
    ...
    
  2. downto(down, iterator)
    Number.prototype.downto = function (down, iterator) {
      for (var i = this.valueOf(); i >= down; i--) {
        iterator(i);
      return this.valueOf();
    };
    
  3. iters()
    Number.prototype.iters = function () {
        return [(this for (x of [0])),
                (this for (y of [0]))];
    };
    var [a, b] = (3).iters();
    var three = a.next();
    assertEq(Object.prototype.toString.call(three), '[object Number]');
    assertEq(+three, 3);
    assertEq(b.next(), three);
    ...
    
  4. upto(from)
    Number.prototype.upto = function (from) {
      var a = [];
      var to = this.valueOf();
      var i = to - 1;
      while (i++ < from) {
        a.push(i);
      return a;
    };
    ...
    
  5. upto(t, cb)
    Number.prototype.upto = function (t, cb) {
      var i = this;
      if(t < this) {
        return +this;
      while (i <= t) {
        cb(i++);
      return +this;
    ...
    
  6. upto(t, cb)
    Number.prototype.upto = function(t, cb) {
      var i = this;
      if(t < this) return +this;
      while (i <= t) { cb(i++); }
      return +this;
    };
    
  7. downto(t, cb)
    Number.prototype.downto = function (t, cb) {
      var i = this;
      if(t > this) {
        return +this;
      while (i >= t) {
        cb(i--);
      return +this;
    ...