# Chapter 8 - Errata

**URL:** <https://forums.kodeco.com/t/chapter-8-errata/98147>\
**Category:** Kotlin Apprentice\
**Created:** [February 13, 2020, 8:26pm UTC](https://forums.kodeco.com/t/chapter-8-errata/98147 "2020-02-13T20:26:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abunur](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/abunur/32/109585_2.png) [@abunur](https://forums.kodeco.com/u/abunur)\
**Post date:** [February 13, 2020, 8:26pm UTC](https://forums.kodeco.com/t/chapter-8-errata/98147/1 "2020-02-13T20:26:59Z")

</div>

> You can also pass a number into the constructor for these types, for example, to create an array of zeros.  
> `val zeros = DoubleArray(4) // 0.0, 0.0, 0.0, 0.0`

The text implies the example will show passing a default value, but the code example does not do this (the 4 is the length of the array, not the default value). This example happens to work because the default value, if one is not provided, is zero. The example should be changed to show a non-zero example and passing that value in the constructor.

---

<div class="post-metadata">

**Author:** ![abunur](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/abunur/32/109585_2.png) [@abunur](https://forums.kodeco.com/u/abunur)\
**Post date:** [March 30, 2020, 8:51pm UTC](https://forums.kodeco.com/t/chapter-8-errata/98147/2 "2020-03-30T20:51:19Z")

</div>

Challenge Two solution at the end of the chapter seems to be wrong.

This is the solution given:

```nohighlight
  // Challenge 2 - Write a function that removes the first occurrence of a given integer from a list of integers. This is the signature of the function:
  // fun removeOne(item: Int, list: List<Int>): List<Int>

  fun removeOne(item: Int, list: List<Int>): List<Int> {
    val mutableList = list.toMutableList()
    mutableList.remove(item)
    return mutableList.toList()
  }

```

1. This is the documentation for remove:  
[remove - Kotlin Programming Language](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/remove.html)  
Note for `MutableList` this is actually deprecated,  
**Deprecated:** Use removeAt(index) instead.  
In Kotlin one should use the [MutableList.removeAt](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/remove-at.html#kotlin.collections.MutableList%24removeAt(kotlin.Int))function instead.

Both for `.remove` and `.removeAt`, the function does not do what the challenge is asking for. The function removes the item at the provided **index**.

So if your List is (3, 3, 3, 3, 4, 4, 0, 9) and you call the function to remove **4** , according to the challenge question the function should return (3, 3, 3, 3, 4, 0, 9)

But what the provided solution does is remove an item at a certain index, not the provided integer. So the solution given, gives the wrong answer in this case. It will remove the fourth item in the list, not the first occurrence of the integer 4, giving (3, 3, 3, 4, 4, 0, 9)

What the solution should do, is iterate through the list until it finds a match for the provided argument, then remove that item, regardless of the index

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [April 6, 2020, 12:04pm UTC](https://forums.kodeco.com/t/chapter-8-errata/98147/3 "2020-04-06T12:04:16Z")

</div>

@abunur Thank you for the heads up - much appreciated! I will forward this to the book team.

---

<div class="post-metadata">

**Author:** ![macsimus](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/macsimus/32/109104_2.png) [@macsimus](https://forums.kodeco.com/u/macsimus)\
**Post date:** [April 6, 2020, 9:10pm UTC](https://forums.kodeco.com/t/chapter-8-errata/98147/4 "2020-04-06T21:10:20Z")

</div>

Thanks for the feedback, @abunur! I believe the solution to Challenge Two is actually correct.

The `remove` function being used in the solution is this one, which is on the same page you linked to:

```kotlin
fun <T> MutableCollection<out T>.remove(element: T): Boolean
Removes a single instance of the specified element from this collection, if it is present

```

For example, running the following code in the Kotlin playground,

```kotlin
val a = mutableListOf(1, 2, 4, 5, 6, 7, 4, 5)
a.remove(4)
println(a)

```

results in the output `[1, 2, 5, 6, 7, 4, 5]`. The first occurrence of 4 (at index 2) is removed.
