Skip to content

Антон Белов home_work_2#9

Open
anbv731 wants to merge 1 commit intoMadBrains:masterfrom
anbv731:a_belov_home_work_2
Open

Антон Белов home_work_2#9
anbv731 wants to merge 1 commit intoMadBrains:masterfrom
anbv731:a_belov_home_work_2

Conversation

@anbv731
Copy link
Copy Markdown

@anbv731 anbv731 commented Feb 23, 2022

No description provided.


//Преобразовать список клиентов в сет
fun Shop.getSetOfCustomers(): Set<Customer> = setOf()
fun Shop.getSetOfCustomers(): Set<Customer> = this.customers.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.

this в котлине не нужен

// Вернуть список клиентов из представленного города
fun Shop.getCustomersFrom(city: City): List<Customer> = listOf()
fun Shop.getCustomersFrom(city: City): List<Customer> =
this.customers.filter { it.city == city }.toList()
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.

.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()
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.

Ошибка. У тебя всегда перезаписывается значение в словаре. То есть всегда только один клиент из города будет, даже если их на самом деле несколько

// Вернуть сет клиентов, у которых не доставленных заказов больше чем заказанных
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 }
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.

.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
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.

та же история что и до этого, можно заменить на count с условием

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