File tree 3 files changed +4
-5
lines changed
3 files changed +4
-5
lines changed Original file line number Diff line number Diff line change 1
1
// Return the sum of prices for all the products ordered by a given customer
2
2
fun moneySpentBy (customer : Customer ): Double =
3
- customer.orders.flatMap { it.products }.sumByDouble { it.price }
3
+ customer.orders.flatMap { it.products }.sumOf { it.price }
Original file line number Diff line number Diff line change 4
4
visible : true
5
5
placeholders :
6
6
- offset : 132
7
- length : 64
7
+ length : 58
8
8
placeholder_text : TODO()
9
9
- name : src/Shop.kt
10
10
visible : true
Original file line number Diff line number Diff line change @@ -5,9 +5,8 @@ the sum of the prices for all the products ordered by a given customer.
5
5
Note that each product should be counted as many times as it was ordered.
6
6
7
7
Use
8
- [ ` sum ` ] ( https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sum.html ) or
9
- [ ` sumOf ` ] ( https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sum-of.html ) .
10
- If you want to sum up double values, use ` sumOfDouble ` .
8
+ [ ` sum ` ] ( https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sum.html ) or
9
+ [ ` sumOf ` ] ( https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sum-of.html ) , if you want to sum up double values.
11
10
12
11
``` kotlin
13
12
listOf (1 , 5 , 3 ).sum() == 9
You can’t perform that action at this time.
0 commit comments