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
25 changes: 23 additions & 2 deletions clean-code-challanges/src/main/java/Anagram.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
* Given a word and a list of possible anagrams, select the correct sublist.
*
* Given "listen" and a list of candidates like "enlists" "google" "inlets" "banana" the program should return a list containing "inlets".
*/
public class Anagram {
private final String templateWord;

public Anagram(String word) {

templateWord = word.toLowerCase();
}

public List<String> match(List<String> candidates) {
return null;
List<String> anagrams;

anagrams = candidates
.stream()
.filter(this::isAnagram)
.collect(Collectors.toList());

return anagrams;
}


private boolean isAnagram(String word){
char[] candidate = word.toLowerCase().toCharArray();
Arrays.sort(candidate);

char[] template = templateWord.toCharArray();
Arrays.sort(template);

return !word.equalsIgnoreCase(templateWord) && Arrays.equals(candidate, template);
}
}
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
@@ -1,3 +1,4 @@
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand All @@ -8,6 +9,7 @@
import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
@Ignore
public class PigLatinTranslatorTest {

private String englishPhrase;
Expand Down