Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: kata/remove-duplicates-from-list #646

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Codewars Handbook ☕️🚀

[![Views statistics +1 👀](https://img.shields.io/badge/dynamic/xml?color=success&label=views&query=//*[name()=%27text%27][3]&url=https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2FParanoidUser%2Fcodewars-handbook)](https://hits.seeyoufarm.com/api/count/graph/dailyhits.svg?url=https://github.com/ParanoidUser/codewars-handbook)
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-68.7%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
[![Completed kata 👌](https://img.shields.io/badge/completed%20kata-68.6%25-red.svg)](https://www.codewars.com/kata/search/java?xids=completed)
[![CI pipeline 🛠](https://img.shields.io/github/actions/workflow/status/ParanoidUser/codewars-handbook/build.yml?branch=main)](https://github.com/ParanoidUser/codewars-handbook/actions/workflows/build.yml)
[![Quality gate 🔎](https://img.shields.io/sonar/alert_status/codewars-handbook?server=https%3A%2F%2Fsonarcloud.io)](https://sonarcloud.io/dashboard?id=codewars-handbook)
[![Let's have a chat! 📞](https://img.shields.io/gitter/room/ParanoidUser/codewars-handbook?color=49c39e)](https://gitter.im/ParanoidUser/codewars-handbook)
Expand All @@ -25,7 +25,7 @@ slug.

| [1 kyu](/kata/1-kyu/index.md) | [2 kyu](/kata/2-kyu/index.md) | [3 kyu](/kata/3-kyu/index.md) | [4 kyu](/kata/4-kyu/index.md) | [5 kyu](/kata/5-kyu/index.md) | [6 kyu](/kata/6-kyu/index.md) | [7 kyu](/kata/7-kyu/index.md) | [8 kyu](/kata/8-kyu/index.md) | [beta](/kata/beta/index.md) | [retired](/kata/retired/index.md) |
|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------------:|
| 0 | 1 | 2 | 26 | 48 | 430 | 578 | 216 | 56 | 79 |
| 0 | 1 | 2 | 26 | 48 | 430 | 578 | 217 | 56 | 79 |

**Note:** The source code is written in Java 17 and may use language features that are incompatible
with Java 8, 11.
Expand Down
1 change: 1 addition & 0 deletions kata/8-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
- [Quarter of the year](quarter-of-the-year)
# R
- [Regexp Basics - is it a digit?](regexp-basics-is-it-a-digit)
- [Remove duplicates from list](remove-duplicates-from-list)
- [Remove exclamation marks](remove-exclamation-marks)
- [Remove First and Last Character](remove-first-and-last-character)
- [Remove String Spaces](remove-string-spaces)
Expand Down
13 changes: 13 additions & 0 deletions kata/8-kyu/remove-duplicates-from-list/README.md
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]
```
7 changes: 7 additions & 0 deletions kata/8-kyu/remove-duplicates-from-list/main/Solution.java
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 kata/8-kyu/remove-duplicates-from-list/test/SolutionTest.java
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));
}
}