Skip to content

Commit

Permalink
refactor(S1121): extract the assignment out of this expression
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser committed Nov 28, 2022
1 parent be28ad3 commit 72fda42
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kata/4-kyu/sum-strings-as-numbers/main/Kata.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ static String sumStrings(String a, String b) {
a = "0".repeat(length - a.length()) + a;
b = "0".repeat(length - b.length()) + b;
var result = new StringBuilder(length);
for (int r = 0, i = length - 1; i >= 0; i--) {
result.insert(0, (r = a.charAt(i) + b.charAt(i) - 96 + (r / 10)) % 10);
int r = 0;
for (int i = length - 1; i >= 0; i--) {
r = r / 10 + a.charAt(i) + b.charAt(i) - 96;
result.insert(0, r % 10);
}
return result.toString().replaceFirst("0*", "");
}
Expand Down

0 comments on commit 72fda42

Please sign in to comment.