You are viewing a single comment's thread. Return to all comments →
Very nice!
That's mine with foldLeft as well: purely functional but with some boilerplate.
class Acc (val min: Int, val max: Int, val nMin: Int, val nMax: Int) object Acc { def apply(a: Int, b: Int, c: Int, d: Int) = new Acc(a,b,c,d) } def count(acc: Acc, elem: Int): Acc = if ( elem > acc.max ) Acc(acc.min, elem, acc.nMin, acc.nMax + 1) else if ( elem < acc.min ) Acc(elem, acc.max, acc.nMin + 1, acc.nMax) else Acc(acc.min, acc.max, acc.nMin, acc.nMax) val res = l.tail.foldLeft(Acc(l.head, l.head, 0, 0))(count)
Seems like cookies are disabled on this browser, please enable them to open this website
Breaking the Records
You are viewing a single comment's thread. Return to all comments →
Very nice!
That's mine with foldLeft as well: purely functional but with some boilerplate.