Complete the code to create a list of numbers from 1 to 5.
val numbers = listOf([1])We use listOf with explicit values separated by commas to create a list.
Complete the code to convert a list to a sequence.
val seq = numbers.[1]()toList() returns a list, not a sequence.map() requires a lambda and does not convert to sequence.The asSequence() function converts a collection to a sequence for lazy operations.
Fix the error in the code to filter even numbers using a sequence.
val evens = numbers.asSequence().filter { it [1] 2 == 0 }.toList()/ instead of modulo %.The modulo operator % checks if a number is divisible by 2 (even).
Fill both blanks to create a sequence that maps numbers to their squares and then converts to a list.
val squares = numbers.[1]().[2] { it * it }.toList()
filter instead of map to transform elements.toList too early, before mapping.First convert to a sequence with asSequence(), then use map to square each number.
Fill all three blanks to create a sequence that filters odd numbers, maps to double their value, and converts to a list.
val result = numbers.[1]().[2] { it % 2 != 0 }.[3] { it * 2 }.toList()
filter and map order.Convert to sequence with asSequence(), filter odd numbers with filter, then double values with map.