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
13 changes: 12 additions & 1 deletion clean-code-challanges/src/main/java/IsogramChecker.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.util.stream.Collectors;

/**
* Determine if a word or phrase is an isogram.
*
Expand All @@ -16,7 +18,16 @@
class IsogramChecker {

boolean isIsogram(String phrase) {
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
final String whiteSpacesAndHyphens = "[\\s\\-]";

String cleanPhrase = phrase.replaceAll(whiteSpacesAndHyphens, "").toLowerCase();

int numberOfUniqueCharacters = cleanPhrase.chars()
.mapToObj(o -> (char)o)
.collect(Collectors.toSet())
.size();

return cleanPhrase.length() == numberOfUniqueCharacters;
}

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

@Ignore

public class IsogramCheckerTest {

@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 @@ -6,8 +7,8 @@
import java.util.Collection;

import static org.junit.Assert.assertEquals;

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

private String englishPhrase;
Expand Down