-
-
Save NKid/2b7824bcbb62a81be1b4 to your computer and use it in GitHub Desktop.
[字串重覆] String Repeat
This file contains 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(str, n) { | |
var tmp = ''; | |
for(var i = 0; i < n; i++) { | |
tmp += str; | |
} | |
return tmp; | |
} | |
console.log(repeat('Toro', 3)); | |
String.prototype.repeat = function(n) { | |
var arr = new Array(n + 1); | |
return arr.join(this); | |
}; | |
console.log('Toro'.repeat(3)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment