simplify `getclosestDay`

pull/8879/head
kraktus 2021-05-07 22:21:45 +02:00
parent 1f41a5eeb2
commit ec0abd4821
2 changed files with 1 additions and 4 deletions

View File

@ -38,7 +38,4 @@ object Maths {
if (normal > mean - deviation && normal < mean + deviation) normal.toInt
else boxedNormalDistribution(mean, deviation, factor)
}
def closestIn(n: Int, iter: Iterable[Int]): Option[Int] =
iter.nonEmpty option iter.minBy(v => math.abs(v - n))
}

View File

@ -43,7 +43,7 @@ object PuzzleDashboard {
val dayChoices = List(1, 2, 3, 7, 10, 14, 21, 30, 60, 90)
def getclosestDay(d: Int): Option[Days] = lila.common.Maths.closestIn(d, dayChoices)
def getclosestDay(n: Int): Option[Days] = dayChoices.minByOption(day => math.abs(day - n))
val topThemesNb = 8