Skip to content

Commit 018c3e1

Browse files
* docs: kata description * feat: kata/evens-times-last --------- Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
1 parent b3ae515 commit 018c3e1

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

kata/7-kyu/evens-times-last/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# [Evens times last](https://www.codewars.com/kata/evens-times-last "https://www.codewars.com/kata/5a1a9e5032b8b98477000004")
2+
3+
Given a sequence of integers, return the sum of all the integers that have an even index, multiplied by the integer at
4+
the last index.
5+
6+
Indices in sequence start from 0.
7+
8+
If the sequence is empty, you should return 0.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import static java.util.stream.IntStream.range;
2+
3+
interface Kata {
4+
static int evenLast(int[] nums) {
5+
return range(0, nums.length).reduce(0, (s, i) -> i % 2 == 0 ? s + nums[i] * nums[nums.length - 1] : s);
6+
}
7+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
import static org.junit.jupiter.params.provider.Arguments.arguments;
3+
4+
import java.util.stream.Stream;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.Arguments;
7+
import org.junit.jupiter.params.provider.MethodSource;
8+
9+
class EvenLastTest {
10+
private static Stream<Arguments> testData() {
11+
return Stream.of(
12+
arguments(new int[0], 0),
13+
arguments(new int[]{2, 2, 2, 2}, 8),
14+
arguments(new int[]{2, 3, 4, 5}, 30),
15+
arguments(new int[]{1, 3, 3, 1, 10}, 140),
16+
arguments(new int[]{-11, 3, 3, 1, 10}, 20)
17+
);
18+
}
19+
20+
@ParameterizedTest
21+
@MethodSource("testData")
22+
void sample(int[] arr, int expected) {
23+
assertEquals(expected, Kata.evenLast(arr));
24+
}
25+
}

kata/7-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
- [E.S.P. Cards](esp-cards "596ef174e4cab6813600004d")
164164
- [Even numbers in an array](even-numbers-in-an-array "5a431c0de1ce0ec33a00000c")
165165
- [Even or Odd - Which is Greater?](even-or-odd-which-is-greater "57f7b8271e3d9283300000b4")
166+
- [Evens times last](evens-times-last "5a1a9e5032b8b98477000004")
166167
- [Excel sheet column numbers](excel-sheet-column-numbers "55ee3ebff71e82a30000006a")
167168
- [Excessively Abundant Numbers](excessively-abundant-numbers "56a75b91688b49ad94000015")
168169
- [Exclamation marks series #5: Remove all exclamation marks from the end of words](exclamation-marks-series-number-5-remove-all-exclamation-marks-from-the-end-of-words "57faf32df815ebd49e000117")

0 commit comments

Comments
 (0)