Skip to content

Kotlin Q1's answer is incorrect #7096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 of 8 tasks
abdallahalaraby opened this issue Feb 25, 2025 · 0 comments
Open
2 of 8 tasks

Kotlin Q1's answer is incorrect #7096

abdallahalaraby opened this issue Feb 25, 2025 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@abdallahalaraby
Copy link

Q1. You would like to print each score on its own line with its cardinal position. Without using var or val, which method allows iteration with both the value and its position?

fun main() {
  val highScores = listOf(4000, 2000, 10200, 12000, 9030)
}

Actual Answer

  • .withIndex()
  • .forEachIndexed()
  • .forEach()
  • .forIndexes()

Expected Answer

  • .withIndex()
  • .forEachIndexed()
  • .forEach()
  • .forIndexes()

Explanation:
withIndex() returns an Sequence<IndexedValue<T>> which still holds a Sequence but does not iterate through it. The correct answer should be .forEachIndexed() which does allow iteration through the Sequence with both the value and its position.

@Ebazhanov Ebazhanov added help wanted Extra attention is needed good first issue Good for newcomers labels Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants