Skip to content

Instantly share code, notes, and snippets.

@bga
Created February 16, 2010 05:52
Show Gist options
  • Save bga/305318 to your computer and use it in GitHub Desktop.
Save bga/305318 to your computer and use it in GitHub Desktop.
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)
return str+str;
var result="";
while(how_many)
{
if(how_many&1)
result+=str;
how_many>>=1;
str+=str;
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment