Last active
January 24, 2019 21:47
-
-
Save Freika/aa534b6ea24811a8aa6bf0d9f1ac410a to your computer and use it in GitHub Desktop.
hexlet help
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SumOfNum = (str) => { | |
let result = 0; | |
let i = 0; | |
while (str.length > i) { | |
result = Number(str[i]) + Number(result); | |
i += 1; | |
} | |
if (String(result).length > 1) { | |
result = SumOfNum(String(result)); | |
} | |
return result; | |
} | |
const addDigits = (num) => { | |
let result = num; | |
result = SumOfNum(String(result)); | |
return result; | |
} | |
console.log(SumOfNum('4687867457')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment