-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscala_excercises
More file actions
102 lines (97 loc) · 2.4 KB
/
scala_excercises
File metadata and controls
102 lines (97 loc) · 2.4 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// ## tuple
//
// val my_tup = (1,2.5,"hello")
//
// val my_tup1 = (3,1,(2,3))
//
// my_tup1._2 //access index start at 1
// my_tup._2._1 //for nested lists
//
// var (pet_name ) = "sammy"
// s"my dogs name is $pet_name"
//
// """ COLLECTIONS """
//
// //LISTS
//
// val evens = List(2,4,6,8,10) //LIST HAS TO BE UPPERCASE
// evens(0) //access elements by its INDEX
// // .tail retrieves everything but the first element
// // .head retrieves the frist element
// val my_list = List(List(1,2,3), List(4,5,6)) // nested LISTS
// my_list.sorted // sort
// my_list.size // pythons length
// my_list.max, my_list.min, my_list.produt
// .drop()
// .takeRight
//
//
// //ARRAYS
//
// //mutable
// //less often used than LISTS
//
// val arrei = Array(1,2,3)
//
// Array.range(0,10)
// Array.range(0,10,2) //same start stop step
//
//
// //SETS
//
// //immutable and immutable
// //doesnt retain an order unlike LISTS
// val s = Set(1,2,3) //immutable,
// val s = collection.mutable,.Set(1,2,3) // mutable
// s += 4 //same as python
// res45: s.type = Set(1, 2, 3, 4)
//
// s.add(100)
// scala.collection.mutable.Set[Int] = Set(1, 100, 2, 3)
// s.max
//
// s.to //allow you to transform it into a set, array, df etc
//
// //MAPS = PYTHON DICTIONARIES
// //doesnt reatain any order
//
// scala> val mymap = Map(("a",1),("b",2),("c",3))
// mymap: scala.collection.immutable.Map[String,Int] = Map(a -> 1, b -> 2, c -> 3)
//
// scala> mymap("a")
// res50: Int = 1
//
// scala> mymap get "a"
// res52: Option[Int] = Some(1)
//
// scala> val mymutablemap = collection.mutable.Map(("x",1),("y",2))
// mymutablemap: scala.collection.mutable.Map[String,Int] = Map(y -> 2, x -> 1)
//
// //add a new value and key
// scala> mymutablemap += ("newkey" -> 999)
// res53: mymutablemap.type = Map(y -> 2, x -> 1, newkey -> 999)
//
// scala> mymap.keys
// res56: Iterable[String] = Set(a, b, c)
//
// scala> mymap.values
// res57: Iterable[Int] = MapLike.DefaultValuesIterable(1, 2, 3)
//
// // array of odd numbers
//
// scala> Range(1,15,2)
// res65: scala.collection.immutable.Range = Range 1 until 15 by
//
// scala> Array.range(1,15,2)
// res67: Array[Int] = Array(1, 3, 5, 7, 9, 11, 13)
//
// scala> val lista = List(1,2,3,4,5,6,6,6)
// lista: List[Int] = List(1, 2, 3, 4, 5, 6, 6, 6)
//
// scala> lista.toSet
// res69: scala.collection.immutable.Set[Int] = Set(5, 1, 6, 2, 3, 4)
""" SCALA LEVEL TWO """
//flow control
if(true){
println("I will print if True")
}