Last active
March 16, 2018 07:09
-
-
Save Beraliv/61b94c26aa8371e5c4175f45970b32bd to your computer and use it in GitHub Desktop.
Task 78. UniLecs. Find a digital root of the number. It equals to sum of all digits until the length is 1.
This file contains 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 digitalRoot = n => { | |
return Math.abs((n - 1) % 9 + 1) | |
} | |
console.log(digitalRoot(1)) // should be 1 | |
console.log(digitalRoot(11)) // should be 2 | |
console.log(digitalRoot(19)) // should be 1 | |
console.log(digitalRoot(191)) // should be 2 | |
console.log(digitalRoot(1918)) // should be 1 | |
console.log(digitalRoot(65536)) // should be 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment