C
Csaba Gabor
I wrote a .repeat(n) function for strings which seemed to work fine:
String.prototype.repeat = function(n) {
// repeats the string n times
if (n<1) return "";
if (n<2) return this;
for (var aStr = [this];--n>0 aStr.push(aStr[0]);
return aStr.join("");
}
Only I was a little surprised to get "object" (instead of "string")
when I tried:
alert (typeof ("x".repeat(1)));
I fixed this by modifying ...
if (n<2) return this+"";
Just something I thought I'd share,
Csaba Gabor from Vienna
String.prototype.repeat = function(n) {
// repeats the string n times
if (n<1) return "";
if (n<2) return this;
for (var aStr = [this];--n>0 aStr.push(aStr[0]);
return aStr.join("");
}
Only I was a little surprised to get "object" (instead of "string")
when I tried:
alert (typeof ("x".repeat(1)));
I fixed this by modifying ...
if (n<2) return this+"";
Just something I thought I'd share,
Csaba Gabor from Vienna