scala> :paste
// Entering paste mode (ctrl-D to finish)
@annotation.tailrec final def indexOfLargestElement(a: Array[Int], i: Int = -1, mi: Int = -1, ma: Int = Int.MinValue): Int = {
val i1 = i + 1
if (i1 < a.length) {
val ai1 = a(i1)
if (ai1 >= ma) indexOfLargestElement(a, i1, i1, ai1)
else indexOfLargestElement(a, i1, mi, ma)
} else mi
}
// Exiting paste mode, now interpreting.
indexOfLargestElement: (a: Array[Int], i: Int, mi: Int, ma: Int)Int
scala> indexOfLargestElement(Array(1, -6, 4, 5, 2, -1))
res0: Int = 3
scala> indexOfLargestElement(Array())
res1: Int = -1
scala> indexOfLargestElement(Array(Int.MinValue))
res2: Int = 0