mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 21:03:58 -05:00
1.6 KiB
1.6 KiB
id, title, challengeType, forumTopicId
| id | title | challengeType | forumTopicId |
|---|---|---|---|
| afcc8d540bea9ea2669306b6 | 重复输出字符串 | 5 | 16041 |
--description--
为num times(第二个参数)重复给定的字符串str (第一个参数)。如果num不是正数,则返回空字符串。如果卡住,请记得使用Read-Search-Ask 。编写自己的代码。
将一个给定的字符串 str(第一个参数)重复输出 num(第二个参数)次。如果 num 不是正数,返回空字符串。在这个挑战中,请不要使用 JavaScript 内置的 .repeat() 方法。
--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));
repeatStringNumTimes("abc", 0) 应返回 ""。
assert(repeatStringNumTimes('abc', 0) === '');