Javascript Number times(cb)

Description

Javascript Number times(cb)


// http://www.codewars.com/kata/ruplesjs-number-1-n-times-do

Number.prototype.times = function (cb) {
  for (let i = 0, n = Math.round(this.valueOf()); i < n; ++i) {
    cb();/*www  .  j  ava 2s .  c om*/
  }
};

Javascript Number times(cb)

Number.prototype.times = function (cb) {
  var i = -1;/*w  w  w  . j  ava  2 s  .  co  m*/

  while (++i < this) {
    cb(i);
  }

  return +this;
};

Javascript Number times(cb)

// Ruby = 5.times { |i| puts i }
// JS   = (1).times(function(i){console.log(i);})
Number.prototype.times = function(cb) {
  var i = -1;/*from w w w.j  ava  2s.co  m*/
  while (++i < this) { cb(i); }
  return +this;
};

Javascript Number times(cb)

Number.prototype.times = function(cb) {
  var i = -1;/* w  w  w.j av  a  2s.c  o m*/
  while (++i < this) {
    cb(i);
  }
  return +this;
};



PreviousNext

Related