We are writing a function that takes a list of objects of type Any and returns a new list, in which all integers (Int) are multiplied by 2, and all other elements are left unchanged.
Write the missing code using the is and !is operators to cast the types.
Type cast and smart cast
Multiply the numbers by 2
Report a typo
Write a program in Kotlin
fun multiplyInts(list: List<Any>): List<Any> {
val result = mutableListOf<Any>()
for (item in list) {
when (item) {
// make your code here
}
}
return result
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.