Repeat Character N Times

后端 未结 23 2542
栀梦
栀梦 2020-11-22 11:51

In Perl I can repeat a character multiple times using the syntax:

$a = \"a\" x 10; // results in \"aaaaaaaaaa\"

Is there a simple way to ac

23条回答
  •  花落未央
    2020-11-22 12:15

    function repeatString(n, string) {
      var repeat = [];
      repeat.length = n + 1;
      return repeat.join(string);
    }
    
    repeatString(3,'x'); // => xxx
    repeatString(10,'

提交回复
热议问题