-
-
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: kata/remove-duplicates-from-list (#646)
- Loading branch information
1 parent
af1e0f7
commit 1827883
Showing
5 changed files
with
48 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
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,13 @@ | ||
# [Remove duplicates from list](https://www.codewars.com/kata/remove-duplicates-from-list "https://www.codewars.com/kata/57a5b0dfcf1fa526bb000118") | ||
|
||
Define a function that removes duplicates from an array of non-negative numbers and returns it as a result. | ||
|
||
The order of the sequence has to stay the same. | ||
|
||
Examples: | ||
|
||
``` | ||
Input -> Output | ||
[1, 1, 2] -> [1, 2] | ||
[1, 2, 1, 1, 3, 2] -> [1, 2, 3] | ||
``` |
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,7 @@ | ||
import static java.util.stream.IntStream.of; | ||
|
||
interface Solution { | ||
static int[] distinct(int[] array) { | ||
return of(array).distinct().toArray(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
kata/8-kyu/remove-duplicates-from-list/test/SolutionTest.java
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,25 @@ | ||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
|
||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
class SolutionTest { | ||
private static Stream<Arguments> testData() { | ||
return Stream.of( | ||
Arguments.of(new int[0], new int[0]), | ||
Arguments.of(new int[]{1}, new int[]{1}), | ||
Arguments.of(new int[]{1, 2}, new int[]{1, 2}), | ||
Arguments.of(new int[]{1, 1, 2}, new int[]{1, 2}), | ||
Arguments.of(new int[]{1, 1, 1, 2, 3, 4, 5}, new int[]{1, 2, 3, 4, 5}), | ||
Arguments.of(new int[]{1, 2, 2, 1, 3, 3, 1, 4, 2, 4, 5, 6, 7, 7, 7}, new int[]{1, 2, 3, 4, 5, 6, 7}) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("testData") | ||
void sample(int[] input, int[] expected) { | ||
assertArrayEquals(expected, Solution.distinct(input)); | ||
} | ||
} |