Javascript Number timesRepeat(f)

Description

Javascript Number timesRepeat(f)


// Takes a function, evaluates it "this" times.
Number.prototype.timesRepeat = function(f){
 for(var i=0; i<this; i++){
  f();/*from  w w w .  j av  a 2  s .c  om*/
 }
}

// Takes an object, gives back a list with the object repeated "this" times.
Number.prototype.times = function(object){
 var l = [];
 this.timesRepeat(function(){l.push(object)});
 return l;
}



PreviousNext

Related