0
0
Kotlinprogramming~10 mins

Take, drop, and chunked in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to take the first 3 elements from the list.

Kotlin
val numbers = listOf(1, 2, 3, 4, 5)
val firstThree = numbers.[1](3)
println(firstThree)
Drag options to blanks, or click blank then click option'
Atake
Bdrop
Cchunked
Dslice
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'drop' will skip elements instead of taking them.
Using 'chunked' splits the list into groups, not just taking elements.
2fill in blank
medium

Complete the code to drop the first 2 elements from the list.

Kotlin
val letters = listOf("a", "b", "c", "d")
val afterDrop = letters.[1](2)
println(afterDrop)
Drag options to blanks, or click blank then click option'
Atake
Bchunked
Cdrop
Dslice
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'take' will select elements instead of skipping them.
Using 'chunked' groups elements but does not drop.
3fill in blank
hard

Fix the error in the code to split the list into chunks of size 2.

Kotlin
val nums = listOf(10, 20, 30, 40, 50)
val chunks = nums.[1](2)
println(chunks)
Drag options to blanks, or click blank then click option'
Achunked
Bdrop
Ctake
Dslice
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'take' or 'drop' will not split the list into chunks.
Using 'slice' requires ranges, not chunk sizes.
4fill in blank
hard

Fill both blanks to take the first 4 elements and then drop 2 from them.

Kotlin
val data = listOf(5, 6, 7, 8, 9)
val result = data.[1](4).[2](2)
println(result)
Drag options to blanks, or click blank then click option'
Atake
Bdrop
Cchunked
Dslice
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing the order of 'take' and 'drop' changes the result.
Using 'chunked' instead of 'drop' or 'take' here is incorrect.
5fill in blank
hard

Fill all three blanks to chunk the list into size 3, then take the first chunk, and drop its first element.

Kotlin
val items = listOf("x", "y", "z", "w", "v", "u")
val processed = items.[1](3).[2](1)[0].[3](1)
println(processed)
Drag options to blanks, or click blank then click option'
Achunked
Btake
Cdrop
Dslice
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'drop' instead of 'take' to select the first chunk will skip chunks and select a different one.
Trying to use 'slice' instead of 'chunked' to split the list.