programming-examples/js/String/Concatenate a specific string for a specific number of times.js

9 lines
309 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
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));