Complete the code to take the first 3 elements from the list.
val numbers = listOf(1, 2, 3, 4, 5) val firstThree = numbers.[1](3) println(firstThree)
The take function returns the first n elements from the list.
Complete the code to drop the first 2 elements from the list.
val letters = listOf("a", "b", "c", "d") val afterDrop = letters.[1](2) println(afterDrop)
The drop function skips the first n elements and returns the rest.
Fix the error in the code to split the list into chunks of size 2.
val nums = listOf(10, 20, 30, 40, 50) val chunks = nums.[1](2) println(chunks)
The chunked function splits the list into sublists of the given size.
Fill both blanks to take the first 4 elements and then drop 2 from them.
val data = listOf(5, 6, 7, 8, 9) val result = data.[1](4).[2](2) println(result)
First, take(4) selects the first 4 elements, then drop(2) removes the first 2 from that selection.
Fill all three blanks to chunk the list into size 3, then take the first chunk, and drop its first element.
val items = listOf("x", "y", "z", "w", "v", "u") val processed = items.[1](3).[2](1)[0].[3](1) println(processed)
First, chunked(3) splits the list into chunks of 3. Then take(1) selects the first chunk (as a singleton list), [0] extracts the chunk list itself, finally drop(1) removes the first element from that chunk.