Javascript Number upto(t, cb)

Description

Javascript Number upto(t, cb)

Number.prototype.upto = function (t, cb) {
  var i = this;//from   w w  w.  j av  a2s .  c  o  m

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

  while (i <= t) {
    cb(i++);
  }

  return +this;
};

Javascript Number upto(t, cb)

// Ruby = 1.upto(5) { |i| puts i }
// JS   = (1).upto(5, function(i){console.log(i);})
Number.prototype.upto = function(t, cb) {
  var i = this;/* w w  w  . j  a va  2  s  .com*/
  if(t < this) return +this;
  while (i <= t) { cb(i++); }
  return +this;
};



PreviousNext

Related