added assignment 6 ex 3
This commit is contained in:
parent
4eba7f3587
commit
f4e417571a
22
src/Assignment6/Ex3.sc
Normal file
22
src/Assignment6/Ex3.sc
Normal file
@ -0,0 +1,22 @@
|
||||
val cities = List("Paris", "London", "Berlin", "Lausanne")
|
||||
val relatives = List("Grandma", "Grandpa", "Aunt Lottie", "Dad")
|
||||
val travellers = List("Pierre-Andre", "Rachel")
|
||||
|
||||
def generatePostcards(cities: List[String], relatives: List[String], travellers: List[String]): List[String] = {
|
||||
for (t <- travellers;
|
||||
r <- relatives;
|
||||
c <- cities) yield s"Dear $r, Wish you were here in $c! Love, $t"
|
||||
}
|
||||
|
||||
def generatePostcards2(cities: List[String], relatives: List[String], travellers: List[String]): List[String] = {
|
||||
for (t <- travellers;
|
||||
r <- relatives;
|
||||
c <- cities;
|
||||
if r.startsWith("G")) yield s"Dear $r, Wish you were here in $c! Love, $t"
|
||||
}
|
||||
|
||||
val cards: List[String] = generatePostcards(cities, relatives, travellers)
|
||||
println(cards.mkString("\n"))
|
||||
|
||||
val cards2: List[String] = generatePostcards2(cities, relatives, travellers)
|
||||
println(cards2.mkString("\n"))
|
Loading…
x
Reference in New Issue
Block a user