Skip to content

Pyatakov_DZ#4

Open
ker73rus wants to merge 1 commit intoMadBrains:masterfrom
ker73rus:Pyatakov_Kirill_DZ_Lec2
Open

Pyatakov_DZ#4
ker73rus wants to merge 1 commit intoMadBrains:masterfrom
ker73rus:Pyatakov_Kirill_DZ_Lec2

Conversation

@ker73rus
Copy link
Copy Markdown

No description provided.

// Вернуть словарь в котором названия городов являются ключами, а значениями - сет клиентов, проживающих в этом городе
fun Shop.groupCustomersByCity(): Map<String, Set<Customer>> = mapOf()
fun Shop.groupCustomersByCity(): Map<String, Set<Customer>> = buildMap {
customers.map { it.city.title }.forEach { put(it, customers.filter { cust -> cust.city.title == it}.toSet()) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сложна!) Вот так можно customers.groupBy { it.city.title }.mapValues { it.value.toSet() }

// Вернуть сет клиентов, у которых не доставленных заказов больше чем заказанных
fun Shop.getCustomersWithMoreUndeliveredOrdersThanDelivered(): Set<Customer> = setOf()
fun Shop.getCustomersWithMoreUndeliveredOrdersThanDelivered(): Set<Customer> = customers.filter { (it.orders.count { order -> order.isDelivered }
< it.orders.count { order -> !order.isDelivered})}.toSet()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно через val (del, undel) = it.orders.partition { it.isDelivered }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants