String.prototype.repeat
Sunny-117 opened this issue · comments
Sunny commented
String.prototype.repeat= function (n) {
let str = this;
let res = ''
while (n) {
res += str;
n--
}
return res
}
console.log('abc'.repeat(3));
kangkang123269 commented
String.prototype.repeat = function(count) {
if (count < 0) {
throw new RangeError("Count must be non-negative");
}
let repeatedString = "";
for (let i = 0; i < count; i++) {
repeatedString += this;
}
return repeatedString;
};