Snippet: Repeat a string
JavaScript
String.prototype.repeatStringNumTimes = function(times) {
let string = this+'';
if(times < 0)
return "";
if(times === 1)
return string;
else
return string + string.repeatStringNumTimes(times - 1);
}
console.log("abc".repeatStringNumTimes(2));