Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bf59836
Fix #33 - https://tour.golang.org/moretypes/1
Muh-Sidik Feb 6, 2020
ccb54e3
Fix #33 - https://tour.golang.org/moretypes/2
Muh-Sidik Feb 6, 2020
30a9dcb
Fix #33 - https://tour.golang.org/moretypes/3
Muh-Sidik Feb 7, 2020
2cd5dec
Fix #33 - https://tour.golang.org/moretypes/4
Muh-Sidik Feb 7, 2020
6d79235
Fix #33 - https://tour.golang.org/moretypes/5
Muh-Sidik Feb 7, 2020
96c7644
Fix #33 - https://tour.golang.org/moretypes/6
Muh-Sidik Feb 7, 2020
04fe945
Fix #33 - https://tour.golang.org/moretypes/7
Muh-Sidik Feb 7, 2020
714ac4a
Fix #33 - https://tour.golang.org/moretypes/8
Muh-Sidik Feb 7, 2020
fe4e287
Fix #33 - https://tour.golang.org/moretypes/9
Muh-Sidik Feb 7, 2020
aa422b8
Fix #33 - https://tour.golang.org/moretypes/10
Muh-Sidik Feb 7, 2020
4853ead
Fix #33 - https://tour.golang.org/moretypes/11
Muh-Sidik Feb 7, 2020
48c390c
Fix #33 - https://tour.golang.org/moretypes/12
Muh-Sidik Feb 7, 2020
f5f8b35
Fix #33 - https://tour.golang.org/moretypes/13
Muh-Sidik Feb 7, 2020
51bca6b
Fix #33 - https://tour.golang.org/moretypes/14
Muh-Sidik Feb 7, 2020
62052b0
Fix #33 - https://tour.golang.org/moretypes/15
Muh-Sidik Feb 7, 2020
9c01247
Fix #33 - https://tour.golang.org/moretypes/16
Muh-Sidik Feb 7, 2020
eb528b6
Fix #33 - https://tour.golang.org/moretypes/17
Muh-Sidik Feb 7, 2020
1dcb076
Fix #33 - https://tour.golang.org/moretypes/18
Muh-Sidik Feb 7, 2020
c79a09f
Fix #33 - https://tour.golang.org/moretypes/19
Muh-Sidik Feb 7, 2020
3075dcc
Fix #33 - https://tour.golang.org/moretypes/20-21
Muh-Sidik Feb 9, 2020
800cc02
Fix #33 - https://tour.golang.org/moretypes/22
Muh-Sidik Feb 9, 2020
a0ea997
Fix #33 - https://tour.golang.org/moretypes/23-24
Muh-Sidik Feb 9, 2020
2029834
Fix #33 - https://tour.golang.org/moretypes/18
Muh-Sidik Feb 11, 2020
cc76b5a
Fix #33 - https://tour.golang.org/moretypes/23
Muh-Sidik Feb 12, 2020
8b26ba2
Fix #33 - https://tour.golang.org/moretypes/23
Muh-Sidik Feb 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sidik/moretypes_1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package sidik

import "fmt"

func type1() {
i := 1000
p := &i
fmt.Println("i before = ",i)

*p = 2000

fmt.Println("i after = ",i)

}
17 changes: 17 additions & 0 deletions sidik/moretypes_10.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package sidik

import "fmt"

func type10() {
s := []int{4,5,3,1,3,8,9}

s = s[1:4]
fmt.Println(s)

s = s[:2]
fmt.Println(s)

s = s[:1]
fmt.Println(s)

}
21 changes: 21 additions & 0 deletions sidik/moretypes_11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sidik

import "fmt"

func type11() {
s := []int{5, 2, 6, 7, 8, 9, 10}
printSlice(s)

s = s[:0]
printSlice(s)

s = s[:4]
printSlice(s)

s = s[2:]
printSlice(s)
}

func printSlice(s []int) {
fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
12 changes: 12 additions & 0 deletions sidik/moretypes_12.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sidik

import "fmt"

func type12() {
var s []int
fmt.Println(s, len(s), cap(s))
if s == nil {
fmt.Println("nil!")
}

}
21 changes: 21 additions & 0 deletions sidik/moretypes_13.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sidik

import "fmt"

func type13() {
a := make([]int , 5)
printSlice2("a", a)

b := make([]int, 0, 5)
printSlice2("b", b)

c := b[:2]
printSlice2("c", c)

d := c[2:5]
printSlice2("d", d)
}

func printSlice2(s string ,x []int) {
fmt.Printf("%s len=%d cap=%d %v\n", s , len(x), cap(x), x)
}
24 changes: 24 additions & 0 deletions sidik/moretypes_14.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package sidik

import (
"fmt"
"strings"
)

func type14() {
board := [][]string {
[]string{"_", "_", "_"},
[]string{"_", "_", "_"},
[]string{"_", "_", "_"},
}

board[0][0] = "X"
board[2][2] = "O"
board[1][2] = "X"
board[1][0] = "O"
board[0][2] = "X"

for i := 0; i < len(board); i++ {
fmt.Printf("%s\n", strings.Join(board[i], ""))
}
}
19 changes: 19 additions & 0 deletions sidik/moretypes_15.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sidik

import "fmt"

func type15() {
var s []int
printSlice3(s)

s = append(s, 1)
printSlice3(s)

s = append(s, 2,3,4)
printSlice3(s)

}

func printSlice3(s []int) {
fmt.Printf("len=%d cap=%d %v\n", len(s), cap(s), s)
}
11 changes: 11 additions & 0 deletions sidik/moretypes_16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sidik

import "fmt"

var poq = []int{1, 2, 4, 8, 16, 32, 64, 128}

func type16() {
for i, v := range poq {
fmt.Printf("2**%d = %d\n", i, v)
}
}
15 changes: 15 additions & 0 deletions sidik/moretypes_17.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package sidik

import "fmt"

func type17() {
ppow := make([]int, 10)
for i := range ppow {
ppow[i] = 1 << uint(i) // 2**i

}

for _, value := range ppow {
fmt.Printf("%d\n", value)
}
}
21 changes: 21 additions & 0 deletions sidik/moretypes_18.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sidik

import (
"golang.org/x/tour/pic"
)

func Pic(dx, dy int) [][]uint8 {
sdx := make([][]uint8, dx)
for y := 0; y < dy; y++ {
sdy := make([]uint8, dy)
for x := 0; x < dx; x++ {
sdy[x] = uint8((x+y)*4)
}
sdx[y] = sdy
}
return sdx
}

func type18() {
pic.Show(Pic)
}
19 changes: 19 additions & 0 deletions sidik/moretypes_19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sidik

import "fmt"

type Vertexx struct {
Lat, Long float64
}

var m map[string]Vertexx

func type19() {
m = make(map[string]Vertexx)
m["Bell Labs"] = Vertexx{
40.68433, -74.39967,
}

fmt.Println(m["Bell Labs"])

}
13 changes: 13 additions & 0 deletions sidik/moretypes_2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package sidik

import "fmt"

type Vertex struct {
X int
Y int
Z int
}

func type2() {
fmt.Println(Vertex{7, 5, 8})
}
20 changes: 20 additions & 0 deletions sidik/moretypes_20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package sidik

import "fmt"

type Vertex4 struct{
Lat, Long float64
}

var mn = map[string]Vertex4{
"Bell Labs" : Vertex4{
40.68433, -74.39967,
},
"Google Inc" : Vertex4{
37.42202, -122.08408,
},
}

func type20() {
fmt.Println(mn)
}
16 changes: 16 additions & 0 deletions sidik/moretypes_21.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package sidik

import "fmt"

type Vertex5 struct {
Lat, Long float64
}

var maa = map[string]Vertex5{
"Bell Labs": {40.68433, -74.39967},
"Google Inc" : {37.42202, -122.08408},
}

func type21() {
fmt.Println(maa)
}
19 changes: 19 additions & 0 deletions sidik/moretypes_22.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sidik

import "fmt"

func type22() {
mm := make(map[string]int)

mm["Answer"] = 42
fmt.Println("The Value: ", mm["Answer"])

mm["Answer"] = 48
fmt.Println("The Value: ", mm["Answer"])

delete(mm, "Answer")
fmt.Println("The Value: ", mm["Answer"])

v, ok := mm["Answer"]
fmt.Println("The Value: ", v ,"Present", ok)
}
22 changes: 22 additions & 0 deletions sidik/moretypes_23.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sidik

import (
"strings"

"golang.org/x/tour/wc"
)

func WordCount(s string) map[string]int {
words := strings.Fields(s)
result := make(map[string]int)

for _, word := range words{
result[word] += 1
}

return result
}

func type23() {
wc.Test(WordCount)
}
21 changes: 21 additions & 0 deletions sidik/moretypes_24.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sidik

import (
"fmt"
"math"
)

func compute(fn func(float64, float64) float64) float64 {
return fn(3, 4)
}

func type24() {
hypot := func (x, y float64) float64 {
return math.Sqrt(x*x + y*y)
}

fmt.Println(hypot(5, 12))

fmt.Println(compute(hypot))
fmt.Println(compute(math.Pow))
}
18 changes: 18 additions & 0 deletions sidik/moretypes_3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package sidik

import "fmt"

type Vertex1 struct {
X int
Y int
Z int
}

func type3() { //mengakses properti struct dengan titik
p := Vertex{8, 4, 10}
p.X = 19
p.Z = 8

fmt.Println(p.X, p.Z)

}
17 changes: 17 additions & 0 deletions sidik/moretypes_4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package sidik

import "fmt"

type Vertex2 struct {
X int
Y int
}

func type4() {
i := Vertex2{2, 3}
p := &i
p.Y = 8

fmt.Println(i)

}
18 changes: 18 additions & 0 deletions sidik/moretypes_5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package sidik

import "fmt"

type Vertex3 struct {
X, Y int
}

var (
v = Vertex3{5, 44} // struct asli
v2 = Vertex3{X:6} // mengakses satu property di struct
v3 = Vertex3{} // struct zzero value
p = &Vertex3{3,4} //pointer struct, harus dengan * jika ingin value yang asli
)

func type5() {
fmt.Println(v, v2, v3, p)
}
Loading