disclaimer: I do not know what is the channel for ...
# android
i
disclaimer: I do not know what is the channel for this problem, so I post here because I am doing in Android I have
Copy code
data class SomeIntegers(val a: Int, val b: Int, val c: Int, val NoCalculateMe: Int)

val list = listOf<SomeIntegers>( //A lot of SomeIntegers )
I want to find the one max value present in the a, b, c into the list I thought to 2 approaches, do
a
So basically what you need is to find max value among
a
,
b
,
c
for every
SomeIntegers
object in a list and then find max value among those max values?
i
this is correct Alexander, and it looks overwhelming my second solution
is that bad?
a
I would do that with something like the following
Copy code
fun SomeIntegers.getMax(): Int = maxOf(a, maxOf(b, c))

val maxValue = list.fold(Int.MIN_VALUE) { currMax, integers ->
    maxOf(currMax, integers.getMax())
}
i
wow thank you very much this looks much more functional than my solution, I am going to read the documentation for what you suggest, Alex do you have some tips on what I can do to improve on this filtering game, I am quite weak
and in the future would love to come up with a solution like yours
s
if you have a list of Int (or an int array I don't remember) you can use the max function (iirc)
i
OK thanks
r
There's also overloads of maxOf which take more than 2 values so you don't need multiple maxOfs
i
folks do you have a resource I can improve in solving these kind of problems please? Will do leetcode, advent code, codewars, help me or I need to do other to become proficient?
the steps i pseudocoded also are working great:
Copy code
val max  = integerList.map { listOf(it.a,it.b, it.c,it.d) }
                        .flatten()
                        .max()
it looks pretty functional
and readable
what do you think? (I am not senior)