Skip to content

Instantly share code, notes, and snippets.

@Chouser
Created May 13, 2011 19:27
Show Gist options
  • Select an option

  • Save Chouser/971149 to your computer and use it in GitHub Desktop.

Select an option

Save Chouser/971149 to your computer and use it in GitHub Desktop.
repeat a string n times, in a couple languages
(defn repeat-string [string num]
(apply str (repeat num string)))
function repeat_string(string, num) {
var acc = [];
for(var i = 0; i < num; ++i) {
acc.push(string);
}
return acc.join("");
}
def repeat_string(string, num)
string * num
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment