* 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>
		
			
				
	
	
		
			90 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			90 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| ---
 | |
| id: 5a23c84252665b21eecc803f
 | |
| title: Sum digits of an integer
 | |
| challengeType: 5
 | |
| forumTopicId: 302331
 | |
| dashedName: 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.
 | |
| 
 | |
| <ul>
 | |
|   <li><b>1</b><sub>10</sub> sums to <b>1</b></li>
 | |
|   <li><b>1234</b><sub>10</sub> sums to <b>10</b></li>
 | |
|   <li><b>fe</b><sub>16</sub> sums to <b>29</b></li>
 | |
|   <li><b>f0e</b><sub>16</sub> sums to <b>29</b></li>
 | |
| </ul>
 | |
| 
 | |
| # --hints--
 | |
| 
 | |
| `sumDigits` should be a function.
 | |
| 
 | |
| ```js
 | |
| assert(typeof sumDigits == 'function');
 | |
| ```
 | |
| 
 | |
| `sumDigits("1")` should return a number.
 | |
| 
 | |
| ```js
 | |
| assert(typeof sumDigits('1') == 'number');
 | |
| ```
 | |
| 
 | |
| `sumDigits("1")` should return `1`.
 | |
| 
 | |
| ```js
 | |
| assert.equal(sumDigits('1'), 1);
 | |
| ```
 | |
| 
 | |
| `sumDigits("12345")` should return `15`.
 | |
| 
 | |
| ```js
 | |
| assert.equal(sumDigits('12345'), 15);
 | |
| ```
 | |
| 
 | |
| `sumDigits("254")` should return `11`.
 | |
| 
 | |
| ```js
 | |
| assert.equal(sumDigits('254'), 11);
 | |
| ```
 | |
| 
 | |
| `sumDigits("fe")` should return `29`.
 | |
| 
 | |
| ```js
 | |
| assert.equal(sumDigits('fe'), 29);
 | |
| ```
 | |
| 
 | |
| `sumDigits("f0e")` should return `29`.
 | |
| 
 | |
| ```js
 | |
| assert.equal(sumDigits('f0e'), 29);
 | |
| ```
 | |
| 
 | |
| `sumDigits("999ABCXYZ")` should return `162`.
 | |
| 
 | |
| ```js
 | |
| assert.equal(sumDigits('999ABCXYZ'), 162);
 | |
| ```
 | |
| 
 | |
| # --seed--
 | |
| 
 | |
| ## --seed-contents--
 | |
| 
 | |
| ```js
 | |
| function sumDigits(n) {
 | |
| 
 | |
| }
 | |
| ```
 | |
| 
 | |
| # --solutions--
 | |
| 
 | |
| ```js
 | |
| 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;
 | |
| }
 | |
| ```
 |