added assignment 6 ex 1

This commit is contained in:
Louis Heredero 2025-04-08 15:03:00 +02:00
parent 41c0b80d8b
commit 76a4f50075
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7

17
src/Assignment6/Ex1.sc Normal file
View File

@ -0,0 +1,17 @@
def flattenList(list: List[Any]): List[Any] = {
list.foldRight(List.empty[Any])(
(e, acc) => {
e match {
case l: List[Any] => flattenList(l) concat acc
case _ => e::acc
}
}
)
}
assert(
flattenList(
List(List(1,1), 2, List(3, List(5, 8)))
) == List(1,1,2,3,5,8)
)