Skip to content

Instantly share code, notes, and snippets.

function repeatStringBinary(str, how_many)
{
how_many|=0; // convert to number and round
str+=""; // convert to string
if(how_many<=0 || str.length==0)
return "";
if(how_many==1)
return str;
if(how_many==2)
function repeatString(str, how_many)
{
how_many|=0; // convert to number and round
str+=""; // convert to string
if(how_many<=0 || str.length==0)
return "";
if(how_many==1)
return str;
if(how_many==2)
// Sorry. Hack fail :(
// "Speedup" in opera and chrome because bugs in webkit (compile return undefined)
// and opera (invalid regexp object return).
// Giant thanks to @jdalton and @diegoperini
var i,n=20000;
var i=0;
var t="";
for(i=0;i<10000;++i)
t+=" a";
var i,n=300000;
var d0=new Date().getTime();
for(i=0;i<n;++i)
"1.5"-0;
alert("-0: "+(new Date().getTime()-d0)+" ms");
var d0=new Date().getTime();
for(i=0;i<n;++i)
+"1.5";