diff --git a/simple-algorithms/array-diff/src/main/java/com/josdem/kata/Differentiator.java b/simple-algorithms/array-diff/src/main/java/com/josdem/kata/Differentiator.java index 49a6a45..ce7f113 100644 --- a/simple-algorithms/array-diff/src/main/java/com/josdem/kata/Differentiator.java +++ b/simple-algorithms/array-diff/src/main/java/com/josdem/kata/Differentiator.java @@ -5,6 +5,6 @@ public class Differentiator { public List diff(List a, List b) { - return a; + return a.stream().filter(number -> !b.contains(number)).toList(); } } diff --git a/simple-algorithms/array-diff/src/test/java/com/josdem/kata/DifferentiatorTest.java b/simple-algorithms/array-diff/src/test/java/com/josdem/kata/DifferentiatorTest.java index 16fb18f..ca7945d 100644 --- a/simple-algorithms/array-diff/src/test/java/com/josdem/kata/DifferentiatorTest.java +++ b/simple-algorithms/array-diff/src/test/java/com/josdem/kata/DifferentiatorTest.java @@ -21,7 +21,7 @@ class DifferentiatorTest { @DisplayName("Get difference") void shouldGetDifferenceInArrays() { assertEquals(List.of(2), differentiator.diff(List.of(1, 2), List.of(1))); - assertEquals(List.of(2, 2), differentiator.diff(List.of(1, 2), List.of(1))); + assertEquals(List.of(2, 2), differentiator.diff(List.of(1, 2, 2), List.of(1))); assertEquals(List.of(1), differentiator.diff(List.of(1, 2, 2), List.of(2))); assertEquals(List.of(1, 2, 2), differentiator.diff(List.of(1, 2, 2), new ArrayList<>())); assertEquals(new ArrayList<>(), differentiator.diff(new ArrayList<>(), List.of(1, 2)));