def deconstructList(xs: List[Int]): List[Int] = xs match
case Nil => Nil
// Deconstruct a list into head and tail using the cons :: operator.
// Then, reverse order by concatenating head to tail.
case y :: ys => deconstructList(ys) ++ List(y)
deconstructList(List(1, 2, 3, 4))
// res0: List[Int] = List(4, 3, 2, 1)
Scala- 40 min
- Guided Project
- Data Science
- PowerShell 7, Python, R, RStudio
We live in an era where reliable data has become an invaluable asset. We’re constantly bombarded with information from…