Refactor assignment 3 and implement alternative Pareto Principle
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
package taxipark
|
||||
package assignment.week3.taxipark
|
||||
|
||||
/*
|
||||
* Task #1. Find all the drivers who performed no trips.
|
||||
@ -49,13 +49,13 @@ fun TaxiPark.findSmartPassengers(): Set<Passenger> = this.allPassengers
|
||||
* Return any period if many are the most frequent, return `null` if there're no trips.
|
||||
*/
|
||||
fun TaxiPark.findTheMostFrequentTripDurationPeriod(): IntRange? {
|
||||
val maxDuration = this.trips
|
||||
val (maxDuration, _) = this.trips
|
||||
.map { trip -> trip.duration / 10 }
|
||||
.groupBy { it }
|
||||
.maxByOrNull { it.value.size }
|
||||
.maxByOrNull { it.value.size } ?: return null
|
||||
|
||||
val startRange = maxDuration?.let { it.key * 10 }
|
||||
return startRange?.let { it.rangeTo(it + 9) }
|
||||
val startRange = maxDuration * 10
|
||||
return startRange.rangeTo(startRange + 9)
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user