Question | Click to View Answer |
What does the following code print? val people = List("lebron", "messi", "ke$ha")
println(people.size)
|
|
What does the following code print? val lyrics = List("all", "that", "i", "know")
println(lyrics.head)
|
The |
What does the following code print? val future = List("soon", "i'll", "be", "60 years old")
println(future.tail)
|
The |
What does the following code print? val spanish = List("como", "j", "balvin", "va")
println(s"${spanish(1)} ${spanish(2)} bobo")
|
|
What does the following code print? val numbers = List(11, 22, 33)
var total = 0
for (i <- numbers) {
total += i
}
println(total)
|
The |
What does the following code print? val odds = List(3, 5, 7)
var result = 1
odds.foreach( (num: Int) => result *= num )
println(result)
|
The |
What does the following code print? val singers = List("shakira", "nicky jam")
var result = singers.map( (s: String) => s"$s is cool" )
println(result)
|
The |
Double all the numbers in the following val nums = List(4, 10, 30)
|
The println( nums.map( (n: Int) => n * 2 ) )
|
What does the following code print? val evens = List(2, 4, 8)
println {
evens.foldLeft(0) { (memo: Int, y: Int) =>
memo + y
}
}
|
The |