Created
November 14, 2013 13:23
Repeat string as many times as you need without any loops.
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
String.prototype.repeat = function(times) { | |
return (new Array(times + 1)).join(this); | |
}; | |
var str = "1".repeat(3); | |
console.log(str); // 111 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment