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/Part_1.kt b/src/Part_1.kt new file mode 100644 index 0000000..16ddab4 --- /dev/null +++ b/src/Part_1.kt @@ -0,0 +1,7 @@ +fun main() { + val numbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + val numbersDoubled = numbers.map(double) + println(numbersDoubled) +} + +val double: (Int) -> Int = {number -> number * 2 } \ No newline at end of file diff --git a/src/Part_2.kt b/src/Part_2.kt new file mode 100644 index 0000000..4ab84b6 --- /dev/null +++ b/src/Part_2.kt @@ -0,0 +1,18 @@ +//filtering the letter J instead of A +fun main(){ + val namesList = listOf("Johnathan", "Dio", "Joseph", "Giorno", "Josuke", "Diego") + + println(filterNames(namesList,lambdaFuncThatTakesListAndReturnsFilteredList)) + +} + +fun filterNames(listName:List, lambdaFunction:(List)->List): List { + + return lambdaFunction(listName) +} + + +var lambdaFuncThatTakesListAndReturnsFilteredList: (List) -> List = + {names:List -> names.filter {it.contains("J")}} + +//I was getting annoyed at how lambda functions work. So, naming reminds me how they work \ No newline at end of file diff --git a/src/Part_3.kt b/src/Part_3.kt new file mode 100644 index 0000000..f09dccb --- /dev/null +++ b/src/Part_3.kt @@ -0,0 +1,7 @@ +val lambdaSortDescending = {a:List -> a.sortedByDescending {it}} + +fun main(){ + val fruits = listOf("apple", "banana", "kiwi", "strawberry", "grape") + println(lambdaSortDescending(fruits)) + +} diff --git a/src/Part_4.kt b/src/Part_4.kt new file mode 100644 index 0000000..63aafaa --- /dev/null +++ b/src/Part_4.kt @@ -0,0 +1,14 @@ +fun main(){ + 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 }) +} + +fun customFilter(numbers: List, filter: (Int) -> Boolean): List { + + var returnType = numbers.filter(filter) + + return returnType + } \ No newline at end of file diff --git a/src/Part_5.kt b/src/Part_5.kt new file mode 100644 index 0000000..555e2cd --- /dev/null +++ b/src/Part_5.kt @@ -0,0 +1,9 @@ +fun main(){ + val numList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + println(processNumbers(numList)) +} + +fun processNumbers(numbers:List):List{ + var numbersFiltered = numbers.filter { it % 2 == 1 } + return numbersFiltered.map { number -> number * number } +} \ No newline at end of file