You are viewing a single comment's thread. Return to all comments →
Scala!
val result = arr.groupBy(x => if (x > 0) 1 else (if (x<0) -1 else 0)).mapValues(y => y.size.toDouble / arr.size) println(result.getOrElse( 1, 0)) // positive println(result.getOrElse(-1, 0)) // negative println(result.getOrElse( 0, 0)) // zeroes
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →
Scala!