roy
roy

Reputation: 361

List Processing Scala

I am in the process of self teaching myself scala. I know java but I'm having a little problem implementing certain programs with scala.

I am reading a book specifically for learning scala and I'm trying to attempt one of the exercises for expanding my knowledge. enter image description here

How would you implement this in scala? I do have some idea on how to start it using Java. Your help is appreciated.

Upvotes: 1

Views: 93

Answers (1)

Nyavro
Nyavro

Reputation: 8866

I think you need something like this:

evalMono(mono: (Double, Double), x:Double) = mono._1 * Math.pow(x, mono._2)

evalPoly(poly: List[(Double, Double), x:Double) = poly.map (item => evalMono(item, x)).sum

Upvotes: 2

Related Questions