Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.6 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
afcc8d540bea9ea2669306b6 Repeat a String Repeat a String 5 16041 repeat-a-string-repeat-a-string

--description--

Repeat a given string str (first argument) for num times (second argument). Return an empty string if num is not a positive number. For the purpose of this challenge, do not use the built-in .repeat() method.

--hints--

repeatStringNumTimes("*", 3) should return "***".

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

repeatStringNumTimes("abc", 3) should return "abcabcabc".

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

repeatStringNumTimes("abc", 4) should return "abcabcabcabc".

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

repeatStringNumTimes("abc", 1) should return "abc".

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

repeatStringNumTimes("*", 8) should return "********".

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

repeatStringNumTimes("abc", -2) should return "".

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

The built-in repeat() method should not be used.

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

repeatStringNumTimes("abc", 0) should return "".

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);