Skip to content

Instantly share code, notes, and snippets.

@Beraliv
Last active March 16, 2018 07:09
Show Gist options
  • Save Beraliv/61b94c26aa8371e5c4175f45970b32bd to your computer and use it in GitHub Desktop.
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.
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