programming-examples/js/String/Concatenate a specific string for a specific number of times.js
2019-11-15 12:59:38 +01:00

9 lines
309 B
JavaScript

repeat = function repeat(str, count) {
if(typeof(count) == "undefined") {
count =1;
}
return count < 1 ? '' : new Array(count + 1).join(str);
}
console.log(repeat('Ha!'));
console.log(repeat('Ha!',2));
console.log(repeat('Ha!',3));