diff --git a/kotlin/Program3/README.md b/kotlin/Program3/README.md new file mode 100644 index 00000000..11c8cce9 --- /dev/null +++ b/kotlin/Program3/README.md @@ -0,0 +1 @@ +Write a program to filter number from list in kotlin diff --git a/kotlin/Program3/filterList.kt b/kotlin/Program3/filterList.kt new file mode 100644 index 00000000..ef4a373a --- /dev/null +++ b/kotlin/Program3/filterList.kt @@ -0,0 +1,19 @@ +fun main(args: Array) { + println("Basic Filter List Function") + val numbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) + val odd = numbers.filter { it % 2 != 0 } + val even = numbers.filter { it % 2 == 0 } + val moreThan10 = numbers.filter { it > 10 } + + println("odd: $odd") + println("even: $even") + println("moreThan10: $moreThan10") + + val listDay= listOf("Senin","Selasa","Senin","Kamis","Jumat","Sabtu","Minggu") + val containsS = listDay.filter { it.contains("s") } + val equal = listDay.filter { it == "Selasa" } + val length = listDay.filter { it.length > 5 } + println("contains S: $containsS") + println("equal: $equal") + println("length: $length") +} \ No newline at end of file diff --git a/kotlin/README.md b/kotlin/README.md index 73c15c50..2e77bcaf 100644 --- a/kotlin/README.md +++ b/kotlin/README.md @@ -4,6 +4,7 @@ | Program No.| Question | | ------- | ------ | | [Program-1](https://github.com/swaaz/basicprograms/blob/814a1e60ae23d81158d8174666f23c9b7419e15e/kotlin/Program1/pattern.kt) | Write a program to print half pyramid using ' * ' -| [Program-2](https://github.com/swaaz/basicprograms/blob/814a1e60ae23d81158d8174666f23c9b7419e15e/kotlin/Program2/extension.kt) | Q2. Write a program to plus and minus with sample of extension function from kotlin +| [Program-2](https://github.com/swaaz/basicprograms/blob/master/kotlin/Program2/extension.kt) | Q2. Write a program to plus and minus with sample of extension function from kotlin +| [Program-3](https://github.com/swaaz/basicprograms/blob/master/kotlin/Program3/filterList.kt) | Write a program to filter number from list in kotlin