-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (30 loc) · 1.17 KB
/
main.go
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
package main
import "fmt"
func main() {
//Arrays
var things [3]int = [3]int{1, 3, 4}
// Don't allow us to create four length array
//var things [3]int = [3]int{1, 3, 4}
// Don't let us declare string
//var things [3]int = [3]int{1, 3, "string"}
//Displaying length of an array
number := [3]int{1, 2, 3}
//fmt.Println(things, number, len(number))
// Computed properties for defining arrays with shorthand variable.
//"d" is not allowed since number len is 3
names := [len(number)]string{"a", "b", "c"}
fmt.Println(things, names)
// Slices (use Arrays)
//You can change the value of a property of both Array and Slices with targeting index [1] and you can return new Slice by using append fn. Append does not work on Arrays
var goals = []int{3, 5, 6}
fmt.Println("goals:", goals)
goals[2] = 10
newSliceByAppendingValue := append(goals, 90)
fmt.Println("goals:", goals, "newSliceByAppendingValue:", newSliceByAppendingValue, "newSliceByAppendingValue length:", len(newSliceByAppendingValue))
//Slice Ranges
fmt.Println("Slice Ranges")
firstRange := goals[0:2]
secondRange := goals[1:]
thirdRange := goals[:2]
fmt.Println(firstRange, secondRange, thirdRange)
}