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 deleted file mode 100644 index a7a5e00..0000000 --- a/src/Main.kt +++ /dev/null @@ -1,3 +0,0 @@ -fun main() { - println("Hello World!") -} \ No newline at end of file diff --git a/src/part1.kt b/src/part1.kt new file mode 100644 index 0000000..e8ce629 --- /dev/null +++ b/src/part1.kt @@ -0,0 +1,7 @@ + +fun main() { + println( + (1..10).toList().map { it * 2 } + ) +} + diff --git a/src/part2.kt b/src/part2.kt new file mode 100644 index 0000000..03f8dba --- /dev/null +++ b/src/part2.kt @@ -0,0 +1,11 @@ +fun main() { + val namesList = listOf("Alice", "Bob", "Amir", "Charlie", "Annie", "David"); + + println(filterNames(namesList, startsWithA )) +} + +fun filterNames(textList: List, callBack: (String) -> Boolean): List { + return textList.filter(callBack); +} + +val startsWithA: (String) -> Boolean = { text -> text.startsWith('A')} \ No newline at end of file diff --git a/src/part3.kt b/src/part3.kt new file mode 100644 index 0000000..bfb6af8 --- /dev/null +++ b/src/part3.kt @@ -0,0 +1,6 @@ +fun main() { + val wordsList = listOf("apple", "banana", "kiwi", "strawberry", "grape"); + val sortedWordsList = wordsList.sortedByDescending { it.length }; + + println(sortedWordsList); +} \ No newline at end of file diff --git a/src/part4.kt b/src/part4.kt new file mode 100644 index 0000000..226c033 --- /dev/null +++ b/src/part4.kt @@ -0,0 +1,13 @@ +fun main() { + val greaterThan5 = customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it > 5 } + val evenNumbers = customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it % 2 == 0 } + val multiplesOf3 = customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it % 3 == 0 } + + println(greaterThan5); + println(evenNumbers); + println(multiplesOf3); +} + +fun customFilter(numbers: List, filter: (Int) -> Boolean): List { + return numbers.filter(filter); +} \ No newline at end of file diff --git a/src/part5.kt b/src/part5.kt new file mode 100644 index 0000000..be4fa5b --- /dev/null +++ b/src/part5.kt @@ -0,0 +1,16 @@ +fun main() { + val numbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + val oddNumbersSquared = processNumbers( + numbers, condition = { it % 2 != 0 }, transform = { it * it } + ) + + println(oddNumbersSquared) +} + +fun processNumbers( + numbers: List, + condition: (Int) -> Boolean, + transform: (Int) -> Int +): List { + return numbers.filter(condition).map(transform) +} \ No newline at end of file