Created
May 13, 2011 19:27
-
-
Save Chouser/971149 to your computer and use it in GitHub Desktop.
repeat a string n times, in a couple languages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn repeat-string [string num] | |
| (apply str (repeat num string))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function repeat_string(string, num) { | |
| var acc = []; | |
| for(var i = 0; i < num; ++i) { | |
| acc.push(string); | |
| } | |
| return acc.join(""); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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