Skip to content

Instantly share code, notes, and snippets.

@NKid
Last active August 19, 2020 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NKid/2b7824bcbb62a81be1b4 to your computer and use it in GitHub Desktop.
Save NKid/2b7824bcbb62a81be1b4 to your computer and use it in GitHub Desktop.
[字串重覆] String Repeat
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