2.0 KiB
2.0 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
afcc8d540bea9ea2669306b6 | Повторіть рядок Повторення рядка | 5 | 16041 | repeat-a-string-repeat-a-string |
--description--
Повторити заданий рядок str
(перший елемент) num
разів (другий елемент). Повернути порожній рядок, якщо num
не є додатнім числом. Для цього завдання не використовуйте вбудований .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) === '');
--seed--
--seed-contents--
function repeatStringNumTimes(str, num) {
return str;
}
repeatStringNumTimes("abc", 3);
--solutions--
function repeatStringNumTimes(str, num) {
if (num < 1) return '';
return num === 1 ? str : str + repeatStringNumTimes(str, num-1);
}
repeatStringNumTimes("abc", 3);