Problem 4 – Find the number of elements of a list P04 (*) Find the number of elements of a list. Example: scala> length(List(1, 1, 2, 3, 5, 8)) res0: Int = 6 I’ve started with writing some tests to verify my future implementation test(“that empty list is of length 0”) { p04.length(List()) should equal(0) […]

# Category: 99-problems

## 99 Scala Problems – 3/99

Problem 3 – Find the Kth element of a list. P03 (*) Find the Kth element of a list. By convention, the first element in the list is element 0. Example: scala> nth(2, List(1, 1, 2, 3, 5, 8)) res0: Int = 2 Return n-th element As the problem seemed easy and straightforward I wrote […]

## 99 Scala Problems Challenge – 2/99

Problem 2 – Find the last but one element of a list P02 (*) Find the last but one element of a list. Example: scala> penultimate(List(1, 1, 2, 3, 5, 8)) res0: Int = 5 Empty list and one element list scenario I’ve started with a test which stated, that both empty and one-element list […]

## 99 Scala Problems Challenge – 1/99

Problem 1 – Find the last element of a list ‘P01 (*) Find the last element of a list. Example: scala> last(List(1, 1, 2, 3, 5, 8)) res0: Int = 8’ One element list scenario I’ve started with a test, which stated, that one-element list should return that element import org.scalatest.{FunSuite, Matchers} class P01Test extends […]