Skip to content

Commit f32846b

Browse files
* docs: kata description * feat: kata/sum-the-strings --------- Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
1 parent d390b1e commit f32846b

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

kata/8-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
- [Sum of differences in array](sum-of-differences-in-array "5b73fe9fb3d9776fbf00009e")
197197
- [Sum of Multiples](sum-of-multiples "57241e0f440cd279b5000829")
198198
- [Sum of positive](sum-of-positive "5715eaedb436cf5606000381")
199+
- [Sum The Strings](sum-the-strings "5966e33c4e686b508700002d")
199200
- [Sum without highest and lowest number](sum-without-highest-and-lowest-number "576b93db1129fcf2200001e6")
200201
- [Surface Area and Volume of a Box](surface-area-and-volume-of-a-box "565f5825379664a26b00007c")
201202
- [Swap Values](swap-values "5388f0e00b24c5635e000fc6")

kata/8-kyu/sum-the-strings/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# [Sum The Strings](https://www.codewars.com/kata/sum-the-strings "https://www.codewars.com/kata/5966e33c4e686b508700002d")
2+
3+
Create a function that takes 2 integers in form of a string as an input, and outputs the sum (also as a string):
4+
5+
Example: (**Input1, Input2 -->Output**)
6+
7+
```
8+
"4", "5" --> "9"
9+
"34", "5" --> "39"
10+
"", "" --> "0"
11+
"2", "" --> "2"
12+
"-5", "3" --> "-2"
13+
```
14+
15+
Notes:
16+
17+
- If either input is an empty string, consider it as zero.
18+
19+
- Inputs and the expected output will never exceed the signed 32-bit integer limit (`2^31 - 1`)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Kata {
2+
static String sumStr(String a, String b) {
3+
return (a.isEmpty() ? 0 : Integer.parseInt(a)) + (b.isEmpty() ? 0 : Integer.parseInt(b)) + "";
4+
}
5+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.CsvSource;
5+
6+
class SolutionTest {
7+
@ParameterizedTest
8+
@CsvSource(textBlock = """
9+
4, 5, 9
10+
34, 5, 39
11+
'', 8, 8
12+
9, '', 9
13+
'', '', 0
14+
""")
15+
void sample(String a, String b, String expected) {
16+
assertEquals(expected, Kata.sumStr(a, b));
17+
}
18+
}

0 commit comments

Comments
 (0)