Adding Scala examples for Chapter 4 and Chapter 5 (#30)
* Add files via upload * Update 01_countdown.scala * Update 02_greet.scala * Update 02_greet.scala * Create scala * Delete scala * Add files via upload * Add files via upload
This commit is contained in:
6
05_hash_tables/scala/01_price_of_groceries.scala
Normal file
6
05_hash_tables/scala/01_price_of_groceries.scala
Normal file
@@ -0,0 +1,6 @@
|
||||
import scala.collection.mutable
|
||||
val book = mutable.Map[String, Double]()
|
||||
book += ("apple" -> 0.67)
|
||||
book += ("milk" -> 1.49)
|
||||
book += ("avocado" -> 1.49)
|
||||
println(book)
|
||||
12
05_hash_tables/scala/02_check_voter.scala
Normal file
12
05_hash_tables/scala/02_check_voter.scala
Normal file
@@ -0,0 +1,12 @@
|
||||
import scala.collection.mutable
|
||||
val voted = mutable.Map[String, Boolean]()
|
||||
def check_voter(name: String): Unit = {
|
||||
if(voted.exists(_ == (name,true))){
|
||||
println("kick them out!")
|
||||
} else{
|
||||
voted += (name -> true)
|
||||
}
|
||||
}
|
||||
check_voter("tom")
|
||||
check_voter("mike")
|
||||
check_voter("mike")
|
||||
Reference in New Issue
Block a user