Skip to content
Open
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
45 changes: 43 additions & 2 deletions src/Main.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
fun main() {
println("Hello World!")
}
val numList = (1..10).toList()
val doubleList = numList.map { it * 2 }
println(doubleList)


val names = listOf("Alice", "Bob", "Amir", "Charlie", "Annie", "David")
val filteredNames = filterNames(names) { it.startsWith( 'A') }
println(filteredNames)


val fruits = listOf("apple", "banana", "kiwi", "strawberry", "grape")
val sortedbylength = fruits.sortedByDescending { it.length }
println(sortedbylength)

println(customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it > 5 })
println( customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it % 2 == 0 })
println( customFilter(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { it % 3 == 0 })



val newList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // Step 1: Create a list of numbers

val sequreNum = processNumbers(newList, { it % 2 != 0 }, { it * it }
)

println(sequreNum)
}

fun filterNames(names: List<String>, checked: (String) -> Boolean): List<String> {
return names.filter(checked)
}

fun customFilter(numbers: List<Int>, filter: (Int) -> Boolean): List<Int> {
return numbers.filter(filter)
}

fun processNumbers(
list: List<Int>,
notEvent: (Int) -> Boolean,
square: (Int) -> Int):
List<Int> {
return list.filter(notEvent).map(square)
}