added assignment 6 ex 1
This commit is contained in:
parent
41c0b80d8b
commit
76a4f50075
17
src/Assignment6/Ex1.sc
Normal file
17
src/Assignment6/Ex1.sc
Normal 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)
|
||||||
|
)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user