diff --git a/.idea/misc.xml b/.idea/misc.xml index 03f397c..10a22f9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/Main.kt b/src/Main.kt index a7a5e00..3db9d62 100644 --- a/src/Main.kt +++ b/src/Main.kt @@ -1,3 +1,41 @@ fun main() { - println("Hello World!") + // Part 1 + val numberList = (1..10).toList() + val doubled = numberList.map {it * 2} + println(doubled) + + // Part 2 + val people = listOf("Alice", "Bob", "Amir", "Charlie", "Annie", "David") + val filteredPeople = filterNames(people) {it.startsWith("A")} + println(filteredPeople) + + // Part 3 + val fruits = listOf("apple", "banana", "kiwi", "strawberry", "grape") + val sortedFruits = fruits.sortedByDescending { it.length } + println(sortedFruits) + + // Part 4 + println(customFilter(numberList) { it > 5 }) + println(customFilter(numberList) { it % 2 == 0 }) + println(customFilter(numberList) { it % 3 == 0 }) + + // Part 5 - Modified for bonus + val result = processNumbers(numberList, {it % 2 != 0} , {it * it}) + println(result) +} + +// Part 2 +fun filterNames(names: List, filter: (String) -> Boolean): List { + return names.filter(filter) +} + +// Part 4 +fun customFilter(numbers: List, filter: (Int) -> Boolean): List { + return numbers.filter(filter) +} + +// part 5 - Modified for bonus +fun processNumbers(numbers: List, filter: (Int) -> Boolean, transform: (Int) -> Int): List { + val evenFilter = numbers.filter(filter) + return evenFilter.map(transform) } \ No newline at end of file