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.5 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
5a23c84252665b21eecc803f Sum digits of an integer 5 302331 sum-digits-of-an-integer

--description--

Write a function that takes a string as a parameter. This string represents a number that can be in any base (less than 37) and return the sum of its digits.

  • 110 sums to 1
  • 123410 sums to 10
  • fe16 sums to 29
  • f0e16 sums to 29

--hints--

sumDigits should be a function.

assert(typeof sumDigits == 'function');

sumDigits("1") should return a number.

assert(typeof sumDigits('1') == 'number');

sumDigits("1") should return 1.

assert.equal(sumDigits('1'), 1);

sumDigits("12345") should return 15.

assert.equal(sumDigits('12345'), 15);

sumDigits("254") should return 11.

assert.equal(sumDigits('254'), 11);

sumDigits("fe") should return 29.

assert.equal(sumDigits('fe'), 29);

sumDigits("f0e") should return 29.

assert.equal(sumDigits('f0e'), 29);

sumDigits("999ABCXYZ") should return 162.

assert.equal(sumDigits('999ABCXYZ'), 162);

--seed--

--seed-contents--

function sumDigits(n) {

}

--solutions--

function sumDigits(n) {
  n += '';
  for (var s = 0, i = 0, e = n.length; i < e; i += 1)
    s += parseInt(n.charAt(i), 36);
  return s;
}