From c6a34ef7ca447ce8e44e9825d1bd742afe08c1cb Mon Sep 17 00:00:00 2001 From: Mishal Alquraini Date: Sat, 15 Feb 2025 21:05:19 +0300 Subject: [PATCH 1/2] finished parts 1-2-3 --- task/.gitignore | 32 +++++++++++++++++++ task/.idea/.gitignore | 3 ++ .../inspectionProfiles/Project_Default.xml | 6 ++++ task/.idea/kotlinc.xml | 10 ++++++ task/.idea/libraries/KotlinJavaRuntime.xml | 17 ++++++++++ task/.idea/misc.xml | 6 ++++ task/.idea/modules.xml | 8 +++++ task/.idea/vcs.xml | 6 ++++ task/src/Main.kt | 21 ++++++++++++ task/task.iml | 15 +++++++++ 10 files changed, 124 insertions(+) create mode 100644 task/.gitignore create mode 100644 task/.idea/.gitignore create mode 100644 task/.idea/inspectionProfiles/Project_Default.xml create mode 100644 task/.idea/kotlinc.xml create mode 100644 task/.idea/libraries/KotlinJavaRuntime.xml create mode 100644 task/.idea/misc.xml create mode 100644 task/.idea/modules.xml create mode 100644 task/.idea/vcs.xml create mode 100644 task/src/Main.kt create mode 100644 task/task.iml diff --git a/task/.gitignore b/task/.gitignore new file mode 100644 index 0000000..3ddbf4c --- /dev/null +++ b/task/.gitignore @@ -0,0 +1,32 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Kotlin ### +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/task/.idea/.gitignore b/task/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/task/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/task/.idea/inspectionProfiles/Project_Default.xml b/task/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/task/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/task/.idea/kotlinc.xml b/task/.idea/kotlinc.xml new file mode 100644 index 0000000..cba7a76 --- /dev/null +++ b/task/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/task/.idea/libraries/KotlinJavaRuntime.xml b/task/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..3e6dc71 --- /dev/null +++ b/task/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/task/.idea/misc.xml b/task/.idea/misc.xml new file mode 100644 index 0000000..f03c948 --- /dev/null +++ b/task/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/task/.idea/modules.xml b/task/.idea/modules.xml new file mode 100644 index 0000000..52cbedd --- /dev/null +++ b/task/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/task/.idea/vcs.xml b/task/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/task/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/task/src/Main.kt b/task/src/Main.kt new file mode 100644 index 0000000..215b08b --- /dev/null +++ b/task/src/Main.kt @@ -0,0 +1,21 @@ + +fun filterNames(names: List, condition: (String) -> Boolean): List { + return names.filter(condition) +} + +val numbers = listOf(1,2,3,4,5,6,7,8,9,10) +val words = listOf("apple", "banana", "kiwi", "strawberry", "grape") + +fun main() { + val doubleNumbers = numbers.map { it * 2 } + + println(doubleNumbers) + + val names = listOf("Alice", "Bob", "Amir", "Charlie", "Annie", "David") + + val filteredNames = filterNames(names) { it.startsWith("A") } + println(filteredNames) + + val sortedWords = words.sortedByDescending { it.length } + println(sortedWords) +} \ No newline at end of file diff --git a/task/task.iml b/task/task.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/task/task.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file From 9ff0c96f392b46016a878824f955d26e2612429b Mon Sep 17 00:00:00 2001 From: Mishal Alquraini Date: Sat, 15 Feb 2025 21:24:30 +0300 Subject: [PATCH 2/2] done --- task/src/Main.kt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/task/src/Main.kt b/task/src/Main.kt index 215b08b..930f0d1 100644 --- a/task/src/Main.kt +++ b/task/src/Main.kt @@ -2,6 +2,24 @@ fun filterNames(names: List, condition: (String) -> Boolean): List { return names.filter(condition) } +fun customFilter(numbers: List, filter: (Int) -> Boolean): List { + return numbers.filter(filter) +} + +fun processNumbers(number: List): List { + val filteredNumbers = number.filter { it % 2 != 0 } + + val squaredNumbers = filteredNumbers.map { it * it } + + return squaredNumbers +} +//fun processNumbers1( +// number: List, +// filter: (Int) -> Boolean, +// transform: (Int) -> Int +//): List { +// return number.filter(filter).map(transform) +//} val numbers = listOf(1,2,3,4,5,6,7,8,9,10) val words = listOf("apple", "banana", "kiwi", "strawberry", "grape") @@ -18,4 +36,21 @@ fun main() { val sortedWords = words.sortedByDescending { it.length } println(sortedWords) + + val numbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + + val greaterThanFive = customFilter(numbers) { it > 5 } + println("Numbers greater than 5: $greaterThanFive") + + val evenNumbers = customFilter(numbers) { it % 2 == 0 } + println("Even numbers: $evenNumbers") + + val multiplesOfThree = customFilter(numbers) { it % 3 == 0 } + println("Multiples of 3: $multiplesOfThree") + + val number = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + + val result = processNumbers(number) + + println(result) } \ No newline at end of file