Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val flightsDatabase = List(
- ("Geneva", "Vienna", 200),
- ("Vienna", "London", 150),
- ("London", "Geneva", 300),
- ("Geneva", "Zurich", 100),
- ("Vienna", "London", 300),
- ("Vienna", "Helsinki", 200)
- )
- //1. Exercise: Find all the flights arriving to London.
- println(flightsDatabase.filter(f => f._2 == "London"))
- //2. Exercise: given a val numbers = List(1, 2, 3, 4), use the map function to make a new list where each number is squared.
- val numbers = List(1, 2, 3, 4)
- val squareNumber = numbers.map(n => n*n)
- println(squareNumber)
- //**why did we get a nested list?
- Because of we get a new list for connecting flight. For creating new list from the original list there created the nested list.
- //3. Exercise: use foreach to print every pair of connecting flights nicely, so that the end user of your search engine doesn't see the parentheses or the List.
- flightsDatabase.foreach(f=>println(s"Deptutare : ${f._1}; Arrival : ${f._2}; Cost : ${f._3}"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement