You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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?
Actual Answer
Expected Answer
Explanation:
withIndex()
returns anSequence<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.The text was updated successfully, but these errors were encountered: