Skip to content

Instantly share code, notes, and snippets.

@Freika
Last active January 24, 2019 21:47
Show Gist options
  • Save Freika/aa534b6ea24811a8aa6bf0d9f1ac410a to your computer and use it in GitHub Desktop.
Save Freika/aa534b6ea24811a8aa6bf0d9f1ac410a to your computer and use it in GitHub Desktop.
hexlet help
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