Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a sequence from a list.
Kotlin
val numbers = listOf(1, 2, 3, 4, 5) val seq = numbers.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using map or filter directly on the list without converting to sequence.
✗ Incorrect
The asSequence() function converts a collection into a sequence, enabling lazy operations.
2fill in blank
mediumComplete the code to filter even numbers from the sequence.
Kotlin
val numbers = sequenceOf(1, 2, 3, 4, 5) val evens = numbers.[1] { it % 2 == 0 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using map instead of filter, which transforms elements but does not select.
✗ Incorrect
The filter function selects elements that satisfy the given condition, here even numbers.
3fill in blank
hardFix the error in the code to map numbers to their squares.
Kotlin
val numbers = sequenceOf(1, 2, 3) val squares = numbers.[1] { it * it }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter which selects elements, not transforms them.
✗ Incorrect
The map function transforms each element, here squaring each number.
4fill in blank
hardFill both blanks to create a sequence of squares of even numbers.
Kotlin
val numbers = listOf(1, 2, 3, 4, 5) val result = numbers.asSequence().[1] { it % 2 == 0 }.[2] { it * it }.toList()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping filter and map order, which changes the result.
✗ Incorrect
First, filter selects even numbers, then map squares them.
5fill in blank
hardFill all three blanks to create a sequence of uppercase strings longer than 3 characters.
Kotlin
val words = listOf("cat", "dog", "elephant", "fox") val result = words.asSequence().[1] { it.length > 3 }.[2] { it.[3]() }.toList()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase instead of uppercase.
Swapping filter and map order.
✗ Incorrect
First, filter selects words longer than 3 letters, then map converts them to uppercase.