String.prototype.repeat = function(count)
{
if ((count |= 0 ) <= 0)
throw new RangeError();
var result = [];
while (count--)
result.push(this);
return result.join('');
};
var start = +new Date;
'foo'.repeat(1000000);
alert(+new Date-start);
String.prototype.repeat = function(count)
{
if ((count |= 0 ) <= 0)
throw new RangeError();
var result = '';
while (count--)
result += this;
return result;
};
var start = +new Date;
'foo'.repeat(1000000);
alert(+new Date-start);
String.prototype.repeat = function(count)
{
if ((count |= 0 ) <= 0)
throw new RangeError();
var result = '';
while (count--)
result.concat(this);
return result;
};
var start = +new Date;
'foo'.repeat(1000000);
alert(+new Date-start);
String.prototype.repeat = function(count)
{
if ((count |= 0 ) <= 0)
throw new RangeError();
return Array(count + 1).join(this);
};
var start = +new Date;
'foo'.repeat(1000000);
alert(+new Date-start);
String.prototype.repeat = function(count)
{
if ((count |= 0 ) <= 0)
throw new RangeError();
var result = '',
self = this;
while (count)
{
if (count & 1)
result += self;
if (count >>= 1)
self += self;
}
return result;
};
var start = +new Date;
'foo'.repeat(1000000);
alert(+new Date-start);
Тесты