Skip to content

Instantly share code, notes, and snippets.

@BartoszDabek
Created February 29, 2020 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BartoszDabek/6e3994e8c4358e608c3f891aaeffaa8f to your computer and use it in GitHub Desktop.
Save BartoszDabek/6e3994e8c4358e608c3f891aaeffaa8f to your computer and use it in GitHub Desktop.
TDD - recruitment task implementation
class FrequencyImpl implements Frequency {
@Override
public Map<Character, Double> analyze(String text) {
if (text == null) {
throw new IllegalArgumentException();
}
text = text.toLowerCase();
Map<Character, Double> characterFrequency = new HashMap<>();
long distintChars = text.chars().distinct().count();
for (Character character: text.toCharArray()) {
characterFrequency.putIfAbsent(character, 1.0 / distintChars);
}
return characterFrequency;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment