The fun part about the digit sum is that it behaves like a modulo with 9, so this here works:
const digitSum = n => n<10 ? n : (n-1) % 9 + 1;
Hey man! This is new, I see this works! Could you please explain (or refer to) the math behind this or how this works as a modulo 9? Thanks!
I can’t really explain it in a few words but I hope this helps: flyingcoloursmaths.co.uk/a-neat-nu... :)
Brilliant Solution , Math Saves the day !
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The fun part about the digit sum is that it behaves like a modulo with 9, so this here works:
const digitSum = n => n<10 ? n : (n-1) % 9 + 1;
Hey man! This is new, I see this works! Could you please explain (or refer to) the math behind this or how this works as a modulo 9? Thanks!
I can’t really explain it in a few words but I hope this helps: flyingcoloursmaths.co.uk/a-neat-nu... :)
Brilliant Solution , Math Saves the day !