Skip to content

Commit 23f4280

Browse files
committed
Add C_UniqueEmailAddresses.java
1 parent a7484cb commit 23f4280

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

src/test/java/com/github/streams/practice/a_easy/numbers/EasyNumbersProblemSolution.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,8 @@ public static long countNumberOfEvenNumbers(final List<Integer> input) {
101101
public static List<Double> convertCelsiusToFahrenheit(final List<Integer> input) {
102102
return input.stream().map(value -> (value * 9.0 / 5.0) + 32).toList();
103103
}
104+
105+
public static List<String> uniqueEmailAddresses(List<String> input) {
106+
return input.stream().distinct().toList();
107+
}
104108
}

src/test/java/com/github/streams/practice/a_easy/numbers/problems/C_SumOfDigits.java

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.streams.practice.a_easy.numbers.problems;
2+
3+
import com.github.streams.practice.a_easy.numbers.EasyNumbersProblemSolution;
4+
import java.util.List;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.Test;
7+
8+
/**
9+
* Imagine you’re building a registration system for a website. Sometimes, due to user error or
10+
* system retries, duplicate emails get stored in your list.
11+
* You want to keep only unique email addresses before sending a newsletter.
12+
*/
13+
class C_UniqueEmailAddresses {
14+
@Test
15+
void uniqueEmailAddresses() {
16+
final var input =
17+
List.of(
18+
19+
20+
"[email protected]", // duplicate
21+
22+
"[email protected]" // duplicate
23+
);
24+
25+
final var mySolution = EasyNumbersProblemSolution.uniqueEmailAddresses(input);
26+
final var yourSolution = List.of();
27+
28+
Assertions.assertEquals(mySolution, yourSolution);
29+
}
30+
}

0 commit comments

Comments
 (0)