I am writing a program to concatenate a string to make it repeat a number of times but on using concat method it always returns an empty string. I have solved the problem using + operator. But I still want to figure why concat is returning empty string.
Here is the code
let repeatStr = (str, num) => {
let newStr = '';
for(let i = 0; i < num; i++){
newStr.concat(str);
}
return newStr;
}
String.prototype.repeatfunction to repeat a string rather than creating a new function