Hi,How it is possible to return array of items if ...
# getting-started
m
Hi,How it is possible to return array of items if there is when inside, how should I modify the else bracnh to get it working fun printAll(type: Int): Array<String> { // 1 return arrayOf( when(type) { 1 -> "one" 2 -> "two" else -> { "three","four" } } ) }
j
Copy code
when(type) {
    1 -> arrayOf("one")
    2 -> arrayOf("two")
    else -> arrayOf("three","four")
}
should be enough 🙂
m
I dont like repetition of code, thereforeI would like the arrayof statment before when
j
well, you can’t without adding runtime computations, which is not worthwhile if you ask me the repetition here is not that much and at least your code is way more readable 😉
m
Ok, thank you for your answer