-
-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isogram : add to track #311
isogram : add to track #311
Conversation
Renamed to make clear the status of this PR. @Kai-Shiro, when you're ready for a review, please rename it back to |
|
||
public static boolean isIsogram(String word){ | ||
|
||
Set<Character> charset= new HashSet<Character>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just use the diamond operator for your HashSet
declaration like this:
Set<Character> charset = new HashSet<>();
|
||
Set<Character> charset= new HashSet<Character>(); | ||
String[] words = word.split(" "); | ||
String newword = concat(words); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Java, the convention is to use camelCase
, as in newWord
.
public static String concat(String[] words){ | ||
String newword = new String(""); | ||
for(int i = 0; i < words.length; i++) | ||
newword = newword + words[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you like, you could replace this with:
String newWord = "";
for (String word: words){
newWord += word;
}
No need for the index variable.
Or, for some extra-delicious Java 8:
public static String concat(String[] words){
return stream(words).collect(joining());
}
To use the Streams
version you'll need to import:
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;
newword = concat(words).toLowerCase(); | ||
|
||
for(int i = 0; i < newword.length(); i++) | ||
charset.add(newword.charAt(i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we like to be explicit with our curly braces, even in short blocks like this.
@Kai-Shiro thanks for doing this! We really appreciate the work. in the spirit of challenging each other to produce the best possible product, I have made a couple of suggestions that are primarily stylistic. I also threw out a couple of alternative implementations that I thought might be interesting to you. Please feel free to use them, or not, as you prefer. Finally, there's a merge conflict with Thanks again. |
@matthewmorgan Thanks for the advices! I have applied some changes to the code and i think i have fixed the merge conflict with |
Nice work @Kai-Shiro ! This implementation is looking much cleaner-- concise, yet still easy to read. If you're up for it, I would like to suggest a couple more changes.
Please let me know if you have any questions, or if you would like help with any of the details. |
@matthewmorgan I have applied some changes.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kai-Shiro this is looking great. I have some minor changes that to request, otherwise bien fait!
@@ -0,0 +1,37 @@ | |||
package exemple; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a typo here, should be:
package example;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, french mistake!
import static java.util.Arrays.stream; | ||
import static java.util.stream.Collectors.joining; | ||
|
||
public class Isogram { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking that the semantics are very close on this class, but not quite right. Think of it this way: what is the purpose of this class? What do the methods do? What if, for example:
IsogramChecker isogramChecker = new IsogramChecker();
String word = "isogram";
boolean result = isogramChecker.isIsogram(word);
assertTrue(iso.isogramChecker()); | ||
} | ||
|
||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll want to annotate all tests except the first one with @Ignore
, so the users can explore their solution using each test as a goalpost.
Nicely done! |
I'll implement the isogram exercise
https://github.com/exercism/x-common/tree/master/exercises/isogram