Complete the code to start an asynchronous task using Kotlin coroutines.
val deferred = scope.[1] { delay(1000L) "Hello" }
The async builder starts a coroutine that returns a Deferred result, which can be awaited later.
Complete the code to wait for the result of an asynchronous task.
val result = deferred.[1]()The await() function suspends until the asynchronous task completes and returns its result.
Fix the error in the code to run two async tasks concurrently and get their results.
val deferred1 = scope.async { fetchData1() }
val deferred2 = scope.async { fetchData2() }
val result1 = deferred1.[1]()
val result2 = deferred2.[1]()Both deferred1 and deferred2 need to be awaited to get their results concurrently.
Fill both blanks to create a map of word lengths for words longer than 3 characters.
val words = listOf("apple", "bat", "carrot", "dog") val lengths = words.filter { it.length [1] 3 }.associateWith { it.[2] }
Filter words with length greater than 3, then map each word to its length property.
Fill all three blanks to create a map of uppercase keys to values greater than zero.
val data = mapOf("a" to 1, "b" to 0, "c" to 3) val result = data.filter { it.value [1] 0 }.mapKeys { it.key.[2]() }.mapValues { it.[3] }
Filter entries with values greater than zero, convert keys to uppercase, and keep the values.