Chapter 3, Mutating while Iterating error?

override fun remove() {
  // 1
  if (index == 1) {
    list.pop()
  } else {
    // 2
    val prevNode = list.nodeAt(index - 2) ?: return
    // 3
    list.removeAfter(prevNode)
    lastNode = prevNode
  }
  index--
}

In step 1 the index should be checked for being 0 not 1.

Hi @kamiwa, Welcome to our community and thank you for your first post. We appreciate your participation and are here to support you. It’s great to have you on board! Thank you for bringing this to our attention.

If you have any further questions or need additional assistance with your code, please feel free to ask!

@zsmb your feedback on this would be appreciated. Thanks