Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/Main.kt

This file was deleted.

7 changes: 7 additions & 0 deletions src/part1.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

fun main() {
println(
(1..10).toList().map { it * 2 }
)
}

11 changes: 11 additions & 0 deletions src/part2.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fun main() {
val namesList = listOf("Alice", "Bob", "Amir", "Charlie", "Annie", "David");

println(filterNames(namesList, startsWithA ))
}

fun filterNames(textList: List<String>, callBack: (String) -> Boolean): List<String> {
return textList.filter(callBack);
}

val startsWithA: (String) -> Boolean = { text -> text.startsWith('A')}
6 changes: 6 additions & 0 deletions src/part3.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fun main() {
val wordsList = listOf("apple", "banana", "kiwi", "strawberry", "grape");
val sortedWordsList = wordsList.sortedByDescending { it.length };

println(sortedWordsList);
}
13 changes: 13 additions & 0 deletions src/part4.kt
Original file line number Diff line number Diff line change
@@ -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<Int>, filter: (Int) -> Boolean): List<Int> {
return numbers.filter(filter);
}
16 changes: 16 additions & 0 deletions src/part5.kt
Original file line number Diff line number Diff line change
@@ -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<Int>,
condition: (Int) -> Boolean,
transform: (Int) -> Int
): List<Int> {
return numbers.filter(condition).map(transform)
}