Javascript String times(count)

Description

Javascript String times(count)


String.prototype.times = function(count) {
  return count < 1 ? '' : new Array(count + 1).join(this);
};

Javascript String times(count)

String.prototype.times = function(count) {
  var results = [];
  var times = count || 1;

  for (var counter = 0; counter < times; counter++) {
    results.push(this);/* w ww . j a  v  a 2s  .co  m*/
  }

  return results.join('');
};



PreviousNext

Related