diff --git a/src/Main.kt b/src/Main.kt index a7a5e00..5fa830f 100644 --- a/src/Main.kt +++ b/src/Main.kt @@ -1,3 +1,44 @@ fun main() { - println("Hello World!") -} \ No newline at end of file + val numList = (1..10).toList() + val doubleList = numList.map { it * 2 } + println(doubleList) + + + val names = listOf("Alice", "Bob", "Amir", "Charlie", "Annie", "David") + val filteredNames = filterNames(names) { it.startsWith( 'A') } + println(filteredNames) + + + val fruits = listOf("apple", "banana", "kiwi", "strawberry", "grape") + val sortedbylength = fruits.sortedByDescending { it.length } + println(sortedbylength) + + println(customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it > 5 }) + println( customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it % 2 == 0 }) + println( customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it % 3 == 0 }) + + + + val newList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // Step 1: Create a list of numbers + + val sequreNum = processNumbers(newList, { it % 2 != 0 }, { it * it } + ) + + println(sequreNum) +} + +fun filterNames(names: List, checked: (String) -> Boolean): List { + return names.filter(checked) +} + +fun customFilter(numbers: List, filter: (Int) -> Boolean): List { + return numbers.filter(filter) +} + +fun processNumbers( + list: List, + notEvent: (Int) -> Boolean, + square: (Int) -> Int): + List { + return list.filter(notEvent).map(square) +}