-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(7-kyu): kata/find-min-and-max (#403)
- Loading branch information
1 parent
d93f0df
commit 2a1d391
Showing
5 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# [Find min and max](https://www.codewars.com/kata/find-min-and-max "https://www.codewars.com/kata/57a1ae8c7cb1f31e4e000130") | ||
|
||
Implement a function that returns the minimal and the maximal value of a list (in this order). |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import java.util.List; | ||
|
||
interface MinMax { | ||
static int[] getMinMax(List<Integer> list) { | ||
var stats = list.stream().mapToInt(i -> i).summaryStatistics(); | ||
return new int[]{stats.getMin(), stats.getMax()}; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
class SolutionTest { | ||
@Test | ||
void sample() { | ||
assertArrayEquals(new int[]{1, 1}, MinMax.getMinMax(List.of(1))); | ||
assertArrayEquals(new int[]{1, 2}, MinMax.getMinMax(List.of(1, 2))); | ||
assertArrayEquals(new int[]{1, 2}, MinMax.getMinMax(List.of(2, 1))); | ||
} | ||
} |
This file contains 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