-
Notifications
You must be signed in to change notification settings - Fork 5
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
develop into master: Challenges | Extra Challenge completed #3
base: master
Are you sure you want to change the base?
Conversation
src/main/java/ChallengeStream.java
Outdated
return new CardWinner(); | ||
var player1Hand = player1.stream() | ||
.sorted(Comparator.comparing((Integer i) -> i).reversed()) | ||
.distinct() |
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'm worried about this distinct
, what if our hand was all the same digits? We would end up with a stream that has only one digit, which is incorrect, because all the other cards are still valid, e.x
[1,2,3,4,5] vs [5,5,5,5,5]
The winning hand for the left player is 54, while the winning hand for the right should be 55, with distinct
I'm thinking you would get only 5
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.
refactored on 32577dd , then tested scenario described in description and passed
src/main/java/ChallengeStream.java
Outdated
double totalCost = switch (callCostObject.getType()) { | ||
case "International" -> | ||
Double.parseDouble(String.format("%.2f", (duration * 7.56) + (extraMinutes * 3.03))); | ||
case "National" -> | ||
Double.parseDouble(String.format("%.2f", (duration * 1.20) + (extraMinutes * 0.48))); | ||
case "Local" -> Double.parseDouble(String.format("%.2f", (duration * 0.2))); | ||
default -> 0D; |
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.
nit: Similar comment as here
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.
refactored on 32577dd including a new method which performs the calculations
src/main/java/ChallengeStream.java
Outdated
.collect(Collectors.groupingBy(CallCostObject::getType)); | ||
|
||
|
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.
nit: This group by operation seems a bit redundant, you could achieve the same with a map
since you're just doing a flatMap
later on in L79
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.
removed and simplified on 32577dd
src/main/java/Challenges.java
Outdated
System.arraycopy(COUNTRY_NAMES, index, tempArray, 0, numberOfElementsToCopy); | ||
System.arraycopy(COUNTRY_NAMES, 0, tempArray, numberOfElementsToCopy, COUNTRY_NAMES.length - numberOfElementsToCopy); | ||
|
||
COUNTRY_NAMES = tempArray.clone(); |
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.
nit: If COUNTRY_NAMES were to be a static variable you would be breaking this function each time you called it, returning tempArray.clone
directly would be less error prone
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.
refactored to directly return it on e235614
src/main/java/Challenges.java
Outdated
String result = String.valueOf(powResult); | ||
|
||
return result.substring(result.length() - lastDigits); |
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.
nit: Think about the solution with modulo described here
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.
refactored solution and used modulo on e235614
src/main/java/Challenges.java
Outdated
for (char c : digits) { | ||
sum = sum.add(new BigDecimal(String.valueOf(c))); | ||
} |
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.
nit: Similar comment as here
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.
refactored solution and used modulo and division on e235614
for (Integer num : ascivalues) { | ||
number += num; | ||
result.append((char) number); | ||
} |
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.
Cleanest one yet!
src/main/java/ChallengeStream.java
Outdated
|
||
import mocks.CallCostObject; | ||
import mocks.CallSummary; | ||
import mocks.CardWinner; | ||
import mocks.TotalSummary; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
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.
nit: usually imports are ordered by putting first libraries (either external or from the STL) and then local imports from other directories.
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.
rearranged on 32577dd
src/main/java/ChallengeStream.java
Outdated
return new CallSummary( | ||
callCostObject, | ||
totalCost | ||
); |
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.
nit: this return could be a single line of code, not worth splitting it.
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.
refactored on 32577dd
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.
Overall good job, besides the comments already given I don't have much to add.
Files that belong to Extra Challenge Solution: modified: pom.xml |
// statistics of all records | ||
statisticsOfRecords(listWeatherDataDTO); | ||
|
||
// statistics of records per day | ||
statisticsOfRecordsPerDay(listWeatherDataDTO); |
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.
Can you think of a way of gathering in results in a single call? So that the JSON is processed only once.
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.
Very clean overall, just left one extra bit to further increase the challenge.
public class StatisticsUtil { | ||
public static Map<String, DoubleSummaryStatistics> calculateDoubleSummaryStatisticsOfObjectAttributes(List<?> records) { |
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.
Why are you using reflection for this?
Completed challenges then executed the commands:
mvn test -Dtests=ChallengesTest.java
mvn test -Dtests=ChallengesTest.java