Graderpractice for programmers

273387 Kotlin - Functions (part 2) The functional part

Awaiting submission
Complete the program to print the list of numbers that are input, using a .forEach (instead of a for loop).
fun main(args: Array) {
    val input = readLine() ?: ""
    val numbers = input.split(' ').map(String::toIntOrNull).filterNotNull()
    // TODO print the numbers
}
Awaiting submission
Write a program that reads in a list of numbers and prints out the numbers doubled using the .map function. Do not use a loop!
Awaiting submission
Write a program that reads a list of words and prints out the total number of letters using the fold function.
fun main(args: Array) {
    val words = (readLine() ?: "").split(' ')
    // TODO
}
Awaiting submission
Write a program that reads a list of words and prints out only the words with less than 4 letters, using the filter function.
Awaiting submission
You are given a program that contains a list of people as follows:
data class Person(val name: String, val age: Int, val gender: Char, val relation: Boolean)

fun main(args: Array) {
    val allPeople = listOf(
      Person("James", 32, 'm', false), Person("Sarah", 25, 'f', false),
      Person("Vera", 57, 'f', false), Person("Deborah", 21, 'f', true),
      Person("Chris", 23, 'm', true), Person("Joanna", 19, 'f', false),
      Person("Cecile", 29, 'f', false), Person("Peter", 36, 'm', false),
      Person("Beryl", 65, 'f', false), Person("Victoria", 29, 'f', true),
      Person("Tony", 17, 'm', true), Person("George", 14, 'm', true))
    
}
Print the ages of all the people.
Awaiting submission
Using the same program as the previous question, print the names of all the male relations (where gender is 'm' and relation is true).
Awaiting submission
Using the same program as the previous question, print the average age of all the people using fold.
Awaiting submission
Using the same code as the previous question, print the gender of the youngest person in the list.