--- id: 5a23c84252665b21eecc803f title: Sum digits of an integer challengeType: 5 --- ## 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.
## Instructions
## Tests
``` yml tests: - text: sumDigits should be a function. testString: assert(typeof sumDigits == 'function', 'sumDigits should be a function.'); - text: sumDigits("1") should return a number. testString: assert(typeof sumDigits("1") == 'number', 'sumDigits("1") should return a number.'); - text: sumDigits("1") should return 1. testString: assert.equal(sumDigits("1"), 1, 'sumDigits("1") should return 1.'); - text: sumDigits("12345") should return 15. testString: assert.equal(sumDigits("12345"), 15, 'sumDigits("12345") should return 15.'); - text: sumDigits("254") should return 11. testString: assert.equal(sumDigits("254"), 11, 'sumDigits("254") should return 11.'); - text: sumDigits("fe") should return 29. testString: assert.equal(sumDigits("fe"), 29, 'sumDigits("fe") should return 29.'); - text: sumDigits("f0e") should return 29. testString: assert.equal(sumDigits("f0e"), 29, 'sumDigits("f0e") should return 29.'); - text: sumDigits("999ABCXYZ") should return 162. testString: assert.equal(sumDigits("999ABCXYZ"), 162, 'sumDigits("999ABCXYZ") should return 162.'); ```
## Challenge Seed
```js function sumDigits (n) { // Good luck! } ```
## Solution
```js function sumDigits (n) { n += '' for (var s=0, i=0, e=n.length; i