freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../basic-algorithm-scripting/repeat-a-string-repeat-a-st...

1.2 KiB
Raw Blame History

id title challengeType videoUrl
afcc8d540bea9ea2669306b6 重复一个字符串重复字符串 5

--description--

num times第二个参数重复给定的字符串str (第一个参数)。如果num不是正数,则返回空字符串。如果卡住,请记得使用Read-Search-Ask 。编写自己的代码。

--hints--

repeatStringNumTimes("*", 3)应该返回"***"

assert(repeatStringNumTimes('*', 3) === '***');

repeatStringNumTimes("abc", 3)应该返回"abcabcabc"

assert(repeatStringNumTimes('abc', 3) === 'abcabcabc');

repeatStringNumTimes("abc", 4)应返回"abcabcabcabc"

assert(repeatStringNumTimes('abc', 4) === 'abcabcabcabc');

repeatStringNumTimes("abc", 1)应该返回"abc"

assert(repeatStringNumTimes('abc', 1) === 'abc');

repeatStringNumTimes("*", 8)应该返回"********"

assert(repeatStringNumTimes('*', 8) === '********');

repeatStringNumTimes("abc", -2)应返回""

assert(repeatStringNumTimes('abc', -2) === '');

不应使用内置的repeat()方法

assert(!/\.repeat/g.test(code));

--solutions--