Files
30-seconds-of-code/snippets/repeatString.md
Angelos Chalaris b74eb9d9bd Linting
2017-12-27 11:02:46 +02:00

329 B

repeatString

Repeats a string n times using String.repeat()

If no string is provided the default is "" and the default number of times is 2.

const repeatString = (str = '', num = 2) => {
  return num >= 0 ? str.repeat(num) : str;
};
// repeatString("abc",3) -> 'abcabcabc'
// repeatString("abc") -> 'abcabc'