I’ve started going through the book: Scala for the Impatient by Cay Horstmann. I’m posting the solution to chapter 4 exercises below.

Advertisements

I’ve started going through the book: Scala for the Impatient by Cay Horstmann. I’m posting the solution to chapter 4 exercises below.

Advertisements

%d bloggers like this:

Param

Thanks for providing your solutions to the exercises in Scala for the Impatient. I have benefited from looking at your answers. Most of the time we solved the problem in the same way. Sometimes you solved it much more elegantly than I did. Only occasionally I solved it more elegantly than you did.

Nice work!

A simpler version of question 9.

def lteqgt(values: Array[Int], v: Int) = (values.count(_v))

def lteqgt(values: Array[Int], v: Int) = (values.count(_v))

Scala doesn’t accept this when I tried it.

scala> def lteqgt(values: Array[Int], v: Int) = (values.count(_v))

:17: error: not found: value _v

def lteqgt(values: Array[Int], v: Int) = (values.count(_v))

Ha. I just realized what happend — this site took out everything between < and >