Kata
Write a function that accepts an integer n and a string s as parameters, and returns a string of s repeated exactly n times.
Examples (input -> output)
6, "I" -> "IIIIII"
5, "Hello" -> "HelloHelloHelloHelloHello"
my answer
function repeatStr (n, s) {
var str="";
for(var i=0; i < n; i++)
str+=s;
return str;
}
function repeatStr (n, s) {
return s.repeat(n);
}
best answer
function repeatStr (n, s) {
return s.repeat(n);
}
Whether you're creating a simple pattern, formatting output, or just need to emphasize a point, the repeat function becomes your trusty companion. It's like having a magic wand that can duplicate your words or characters with a single command!
https://vocal.media/authors/njmc-direct
https://www.credly.com/users/njmcdirectpage/badges
https://hub.docker.com/u/njmcdirectpage