Open
Conversation
Antol
approved these changes
Feb 24, 2022
| @@ -1,3 +1,5 @@ | |||
| package com.example.hw2 | |||
|
|
||
| // Вернуть сет городов в которых проживают клиенты | ||
| fun Shop.getCitiesCustomersAreFrom(): Set<City> = setOf() | ||
| fun Shop.getCitiesCustomersAreFrom(): Set<City> { |
Contributor
There was a problem hiding this comment.
В общем правильно и так, но можно писать в одну строку, если функция маленькая
fun Shop.getCitiesCustomersAreFrom(): Set<City> = customers.map({it.city}).toSet()
| fun Shop.getCustomersWithMoreUndeliveredOrdersThanDelivered(): Set<Customer> = setOf() | ||
| fun Shop.getCustomersWithMoreUndeliveredOrdersThanDelivered(): Set<Customer> { | ||
| return customers.filter { it -> | ||
| it.orders.count { it.isDelivered } < it.orders.count { !it.isDelivered } |
Contributor
There was a problem hiding this comment.
Отлично. Как альтернатива еще partition
| fun Customer.getMostExpensiveDeliveredProduct(): Product? { | ||
| return orders.filter { it.isDelivered }.flatMap { it -> | ||
| it.products.sortedBy { it.price } | ||
| }.lastOrNull() |
Contributor
There was a problem hiding this comment.
Ошибка . У тебя сортируются продукты перед добавлением в общую коллекцию.
Если будет ситуация например такая (оба заказа доставлены):
[
order {
product(100),
product(10),
},
order {
product(10),
product(1),
}
]
То в твоем случае наибольшая цена будет 10, а не 100 как должно быть
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.