-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.3.scala
25 lines (20 loc) · 817 Bytes
/
4.3.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
object act43 extends App{
def toUpper(input:String):String ={
input.toUpperCase()
}
def toLower(input:String):String = {
input.toLowerCase()
}
def formatNames(name:String)(format:String => String):String ={
format(name)
}
val names = List("Benny","Niroshan","Saman","Kumara")
val formattedNames = names.map{
case "Benny" => formatNames("Benny")(toUpper)
case "Niroshan" => formatNames("Niroshan")(name => name.substring(0,2).toUpperCase + name.substring(2))
case "Saman" => formatNames("Saman")(toLower)
case "Kumara" => formatNames("Kumara")(name => name.substring(0,1).toUpperCase + name.substring(1,5).toLowerCase + name.substring(5).toUpperCase)
case other => other
}
formattedNames.foreach(println)
}