I currently have 2 arrays, both of which contain 5 objects. All objects contain variables Int.
Sample data:
data class Demo(val number: Int, val name: String)
val a = Demo(12, "a")
val b = Demo(1, "b")
val c = Demo(3, "c")
val d = Demo(5, "d")
val e = Demo(17, "e")
val array1 = arrayOf(a,b,c,d,e)
val f = Demo(3, "f")
val g = Demo(8, "g")
val h = Demo(15, "h")
val i = Demo(16, "i")
val j = Demo(22, "j")
val array2 = arrayOf(f,g,h,i,j)
//val array3 = ??
What I'm trying to do is create a function that will filter these arrays at maximum values. Now I know that Kotlin has a method in their array with a name max()that will return the maximum value of the array used.
This made me think (I am currently using a nested for-loop, like someone in Java.) Is there a visually beautiful faster / better way to do this in Kotlin?
Expected Result Using Sample Data:
array3[22,17,16,15,12]