diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..3575a72 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..167d83b --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..48de0f4 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6b39356 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..c8397c9 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/kotlin/mate/academy/ProcessAndFilterNumbers.kt b/src/main/kotlin/mate/academy/ProcessAndFilterNumbers.kt index 20d40f2..ca3fa68 100644 --- a/src/main/kotlin/mate/academy/ProcessAndFilterNumbers.kt +++ b/src/main/kotlin/mate/academy/ProcessAndFilterNumbers.kt @@ -1,5 +1,15 @@ package mate.academy -fun processAndFilterNumbers(numbers: List): List { +/** + * Transform each number: if even -> half, if odd -> doubled, then return only values > 25. + * Implemented using a Sequence to avoid creating intermediate lists for large inputs. + */ +const val THRESHOLD = 25 +const val EVEN_DIVISOR = 2 +const val ODD_MULTIPLIER = 2 +fun processAndFilterNumbers(numbers: List): List = + numbers.asSequence() + .map { if (it % 2 == 0) it / EVEN_DIVISOR else it * ODD_MULTIPLIER } + .filter { it > THRESHOLD } + .toList() -}