Nodejs Number Iterate downto(t, cb)

Here you can find the source of downto(t, cb)

Method Source Code

Number.prototype.downto = function (t, cb) {
  var i = this;/*from ww  w. j a va 2 s .co m*/

  if(t > this) {
    return +this;
  }

  while (i >= t) {
    cb(i--);
  }

  return +this;
};

Related

  1. 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);
    ...
    
  2. upto(up, iterator)
    Number.prototype.upto = function (up, iterator) {
      for (var i = this.valueOf(); i <= up; i++) {
        iterator(i);
      return this.valueOf();
    };
    
  3. 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;
    };
    ...
    
  4. upto(t, cb)
    Number.prototype.upto = function (t, cb) {
      var i = this;
      if(t < this) {
        return +this;
      while (i <= t) {
        cb(i++);
      return +this;
    ...
    
  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. downto(t, cb)
    Number.prototype.downto = function(t, cb) {
      var i = this;
      if(t > this) return +this;
      while (i >= t) { cb(i--); }
      return +this;
    };
    
  7. downto(to)
    Number.prototype.downto = function (to) {
      var a = [];
      var from = this.valueOf();
      var i = from + 1;
      while (i-- > to) {
        a.push(i);
      return a;
    };
    ...