String repeat

front·2022년 11월 11일

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);
}
profile
그냥 하기

1개의 댓글

comment-user-thumbnail
2023년 12월 23일

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

답글 달기