Open
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #157 +/- ##
=============================================
+ Coverage 88.39% 88.98% +0.59%
- Complexity 492 524 +32
=============================================
Files 109 117 +8
Lines 1043 1099 +56
Branches 178 195 +17
=============================================
+ Hits 922 978 +56
Misses 106 106
Partials 15 15
Continue to review full report at Codecov.
|
carledriss
reviewed
Sep 12, 2017
| while (num != 0) { | ||
| mod = num % 10; | ||
| num = num / 10; | ||
| res = res + mod; |
Contributor
There was a problem hiding this comment.
This should be
res += mod;
carledriss
reviewed
Sep 12, 2017
| assertEquals("Nope!", digital.sumOfDigits(132189), 6); | ||
| assertEquals("Nope!", digital.sumOfDigits(493193), 2); | ||
| assertEquals("Nope!", digital.sumOfDigits(54), 9); | ||
| assertEquals("Nope!", digital.sumOfDigits(100), 1); |
Contributor
There was a problem hiding this comment.
Please update this
expectedResult is first than actualResult. :)
carledriss
reviewed
Sep 12, 2017
| num = num / 10; | ||
| res += mod; | ||
| } | ||
| return res >= 10 ? sumOfDigits(res) : res; |
Contributor
There was a problem hiding this comment.
In order to avoid some unnecessary variables.
Try this.
public int sumOfDigits(int num) {
int res = 0;
while (num != 0) {
res += num % 10;
num = num / 10;
}
return res >= 10 ? sumOfDigits(res) : res;
}
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this kata, you must create a digital root function.
A digital root is the recursive sum of all the digits in a number. Given n, take the sum of the digits of n. If that value has two digits, continue reducing in this way until a single-digit number is produced. This is only applicable to the natural numbers.
Here's how it works (Ruby example given):
digital_root(16)
=> 1 + 6
=> 7
digital_root(942)
=> 9 + 4 + 2
=> 15 ...
=> 1 + 5
=> 6
digital_root(132189)
=> 1 + 3 + 2 + 1 + 8 + 9
=> 24 ...
=> 2 + 4
=> 6
digital_root(493193)
=> 4 + 9 + 3 + 1 + 9 + 3
=> 29 ...
=> 2 + 9
=> 11 ...
=> 1 + 1
=> 2