Javascript Number times(iterator)

Introduction

Javascript Number times(iterator)

/**/*w  ww.  ja v  a  2  s  .c  o  m*/
 * Runs the given iterator N times
 * @module Number
 * @param {function} iterator
 * @example
 *     (2).times(function(){ });
**/
Number.prototype.times = function(iterator) {
  var index = 0;
  while(index < this) iterator(index++);
  return this
};

Javascript Number times(iterator)

Number.prototype.times = function (iterator) {
  for (var i = 0; i < this; i++) {
    iterator(i);/*from   w  w w  . j ava  2 s  .com*/
  }
};



PreviousNext

Related