Skip to content
Open
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
2 changes: 1 addition & 1 deletion clean-code-challanges/src/main/java/Acronym.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Acronym {

Acronym(String phrase) {

// FOOO
}

String get() {
Expand Down
23 changes: 21 additions & 2 deletions clean-code-challanges/src/main/java/Anagram.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
* Given a word and a list of possible anagrams, select the correct sublist.
Expand All @@ -7,11 +10,27 @@
*/
public class Anagram {

public Anagram(String word) {
private final String word;

public Anagram(String word) {
this.word = word;
}

public List<String> match(List<String> candidates) {
return null;
List<String> foundAnagrams = new ArrayList<>();
char[] wordChars = this.word.toLowerCase().toCharArray();

Arrays.sort(wordChars);

for (String candidate : candidates) {
char[] candidateChars = candidate.toLowerCase().toCharArray();
Arrays.sort(candidateChars);
Comment on lines +26 to +27

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Da du sowieso zweimal sortieren musst, hätte ich dies in eine Methode umgewandelt z.b sortLetters(). So kannst du wiederholenden Code vermeiden. Zitat Marco Rensch: "Wiederholende Code isch schlecht!" ;-)

if(Arrays.equals(wordChars,candidateChars) && !this.word.equalsIgnoreCase(candidate)){
foundAnagrams.add(candidate);
}
}

return foundAnagrams;

}
}
1 change: 0 additions & 1 deletion clean-code-challanges/src/test/java/AcronymTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import static org.junit.Assert.assertEquals;

@Ignore
public class AcronymTest {

@Test
Expand Down
2 changes: 1 addition & 1 deletion clean-code-challanges/src/test/java/AnagramTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@Ignore

public class AnagramTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@Ignore
public class IsogramCheckerTest {

@Test
Expand Down