We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 327506f commit 6020c7fCopy full SHA for 6020c7f
tp8/src/main/kotlin/fmt/kotlin/fundamentals/Cellar.kt
@@ -4,7 +4,9 @@ data class Vineyard(
4
val cellars: List<Cellar>
5
) {
6
7
- fun countBottles() = emptyMap<String, Int>()
+ fun countBottles() = cellars.fold(emptyMap<String, Int>()) { res, cellar ->
8
+ res.merge(cellar.bottles.groupingBy { it.name }.eachCount()) { n, m -> n + m }
9
+ }
10
}
11
12
data class Cellar(
0 commit comments