Open
Conversation
Antol
approved these changes
Feb 24, 2022
|
|
||
| //Преобразовать список клиентов в сет | ||
| fun Shop.getSetOfCustomers(): Set<Customer> = setOf() | ||
| fun Shop.getSetOfCustomers(): Set<Customer> = this.customers.toSet() |
| // Вернуть список клиентов из представленного города | ||
| fun Shop.getCustomersFrom(city: City): List<Customer> = listOf() | ||
| fun Shop.getCustomersFrom(city: City): List<Customer> = | ||
| this.customers.filter { it.city == city }.toList() |
| // Вернуть словарь в котором названия городов являются ключами, а значениями - сет клиентов, проживающих в этом городе | ||
| fun Shop.groupCustomersByCity(): Map<String, Set<Customer>> = mapOf() | ||
| fun Shop.groupCustomersByCity(): Map<String, Set<Customer>> = | ||
| this.customers.map { it.city.title to mutableSetOf(it) }.toMap() |
Contributor
There was a problem hiding this comment.
Ошибка. У тебя всегда перезаписывается значение в словаре. То есть всегда только один клиент из города будет, даже если их на самом деле несколько
| // Вернуть сет клиентов, у которых не доставленных заказов больше чем заказанных | ||
| fun Shop.getCustomersWithMoreUndeliveredOrdersThanDelivered(): Set<Customer> = setOf() | ||
| fun Shop.getCustomersWithMoreUndeliveredOrdersThanDelivered(): Set<Customer> = | ||
| this.customers.filter { it.orders.filter { !it.isDelivered }.size > it.orders.filter { it.isDelivered }.size } |
Contributor
There was a problem hiding this comment.
.filter { !it.isDelivered }.size можно заменить на .count{ !it.isDelivered }
| // Вернуть число - сколько раз был заказан выбранный продукт | ||
| fun Shop.getNumberOfTimesProductWasOrdered(product: Product): Int = 0 No newline at end of file | ||
| fun Shop.getNumberOfTimesProductWasOrdered(product: Product): Int = | ||
| this.customers.map { it.orders.flatMap { it.products }.filter { it == product } }.size No newline at end of file |
Contributor
There was a problem hiding this comment.
та же история что и до этого, можно заменить на count с условием
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.