Skip to content

Commit

Permalink
Update task.md
Browse files Browse the repository at this point in the history
language checked
  • Loading branch information
stephen-hero authored Sep 26, 2023
1 parent 281508c commit 4cb5eab
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions duckShopServer/duckShopServerAddElements/task.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In this task you need to implement functions to be able to
In this task, you need to implement functions to be able to
add ducks to the Duck Shop.

### Task
Expand All @@ -7,10 +7,10 @@ Implement three versions of the `addRandomDuck` function from the `GameChangeFun
the `org.jetbrains.kotlin.course.duck.shop.functions.change` package.
These functions should add a random duck from a list, set, or a map.

Note, you need _actually_ to add a new duck, it means for the cases with a set and a map you
Note, you need to _actually_ add a new duck, which means that in the cases with a set and a map, you
need to generate a duck that is not present in the collection and add it.

After implementing this task the `Add` button in all three modes becomes alive:
After implementing this task, the `Add` button in all three modes becomes alive:

![Current state](../../utils/src/main/resources/images/duck/shop/states/state_5.gif)

Expand All @@ -22,7 +22,7 @@ If you have any difficulties, **hints will help you solve this task**.

<div class="hint" title="How to add a new item into a list or set?">

To add a new item you can use the `add` built-in function:
To add a new item, you can use the built-in `add` function:
```kotlin
val listOfNumbers = mutableListOf(1, 2, 3)
listOfNumbers.add(4)
Expand All @@ -33,7 +33,7 @@ setOfNumbers.add(4)
println(setOfNumbers) // 1, 2, 3, 4
```

Note, that if you try to add the _same_ element to the set, it will not be added.
Note that if you try to add the _same_ element to the set, it will not be added.
</div>

<div class="hint" title="How to add a new item into a map?">
Expand All @@ -45,9 +45,9 @@ myMap[3] = "three"
println(myMap) // 1 to "one", 2 to "two", 3 to "three"
```

In this case if you try to use an existing key, the old key will be replaced with the new one.
In this case, if you try to use an existing key, the old key will be replaced with the new one.

If you need to put something only if it is absent, you can use the `putIfAbsent` built-in function:
If you need to put something only if it is absent, you can use the built-in `putIfAbsent` function:
```kotlin
val myMap = mutableMapOf(1 to "one", 2 to "two")
myMap.putIfAbsent(3, "three")
Expand All @@ -58,7 +58,7 @@ println(myMap) // 1 to "one", 2 to "two", 3 to "three"

<div class="hint" title="How to find the difference between two lists?">

You can use the `minus` built-in function, to make the call more efficient convert one of the argument to the set:
You can use the built-in `minus` function to make the call more efficient and convert one of the arguments of the set:
```kotlin
val listOfNumbers1 = listOf(1, 2, 3, 4, 5)
val listOfNumbers2 = listOf(1, 2, 3)
Expand Down

0 comments on commit 4cb5eab

Please sign in to comment.