is there a way to do this less copy-pasty that isn...
# announcements
l
is there a way to do this less copy-pasty that isn't completely over-engineered ?
a
how about making another function and pass a normal and reversed array?
just a sum fun
b
Copy code
fun diagonalDifference(arr: Array<Array<Int>>): Int {
    return arr.foldIndexed(0) { index, accumulator, element ->
        accumulator + element[index] - element[element.lastIndex - index]
    }.abs()
}
🧙‍♂️ 3
l
@bezrukov that's a genious solution. though i have to comment that
Int.abs()
doesnt exist (you probably meant
Int.absoluteValue
). thanks
b
yep, sure