// // demo of some simple functions on arrays implemented with collection methods // import scala.io.StdIn._ // get array of doubles from stdin, prompting for size first def readArray() : Array[Double] = { println("enter number of values") val sz = readInt Array.fill(sz)( { println("next value?") readDouble }) } // print array values def printArray(a:Array[Double]) { a.foreach(println(_)) } // reduction functions from array-demo rewritten to use collection methods // (but it doesn't really make sense to have such functions -- simpler to // just use the collection methods directly) def newSumArray(a:Array[Double]) : Double = { a.sum } def newProductArray(a:Array[Double]) : Double = { a.product } def newMaxArray(a:Array[Double]) : Double = { a.max } def newMinArray(a:Array[Double]) : Double = { a.min }