-
Notifications
You must be signed in to change notification settings - Fork 3
Fix #33 - https://tour.golang.org/moretypes/23-24 #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Muh-Sidik
wants to merge
25
commits into
pondok-programmer:master
Choose a base branch
from
Muh-Sidik:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 ccb54e3
Fix #33 - https://tour.golang.org/moretypes/2
Muh-Sidik 30a9dcb
Fix #33 - https://tour.golang.org/moretypes/3
Muh-Sidik 2cd5dec
Fix #33 - https://tour.golang.org/moretypes/4
Muh-Sidik 6d79235
Fix #33 - https://tour.golang.org/moretypes/5
Muh-Sidik 96c7644
Fix #33 - https://tour.golang.org/moretypes/6
Muh-Sidik 04fe945
Fix #33 - https://tour.golang.org/moretypes/7
Muh-Sidik 714ac4a
Fix #33 - https://tour.golang.org/moretypes/8
Muh-Sidik fe4e287
Fix #33 - https://tour.golang.org/moretypes/9
Muh-Sidik aa422b8
Fix #33 - https://tour.golang.org/moretypes/10
Muh-Sidik 4853ead
Fix #33 - https://tour.golang.org/moretypes/11
Muh-Sidik 48c390c
Fix #33 - https://tour.golang.org/moretypes/12
Muh-Sidik f5f8b35
Fix #33 - https://tour.golang.org/moretypes/13
Muh-Sidik 51bca6b
Fix #33 - https://tour.golang.org/moretypes/14
Muh-Sidik 62052b0
Fix #33 - https://tour.golang.org/moretypes/15
Muh-Sidik 9c01247
Fix #33 - https://tour.golang.org/moretypes/16
Muh-Sidik eb528b6
Fix #33 - https://tour.golang.org/moretypes/17
Muh-Sidik 1dcb076
Fix #33 - https://tour.golang.org/moretypes/18
Muh-Sidik c79a09f
Fix #33 - https://tour.golang.org/moretypes/19
Muh-Sidik 3075dcc
Fix #33 - https://tour.golang.org/moretypes/20-21
Muh-Sidik 800cc02
Fix #33 - https://tour.golang.org/moretypes/22
Muh-Sidik a0ea997
Fix #33 - https://tour.golang.org/moretypes/23-24
Muh-Sidik 2029834
Fix #33 - https://tour.golang.org/moretypes/18
Muh-Sidik cc76b5a
Fix #33 - https://tour.golang.org/moretypes/23
Muh-Sidik 8b26ba2
Fix #33 - https://tour.golang.org/moretypes/23
Muh-Sidik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!") | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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], "")) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"]) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
Muh-Sidik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| words := strings.Fields(s) | ||
| result := make(map[string]int) | ||
|
|
||
| for _, word := range words{ | ||
| result[word] += 1 | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| func type23() { | ||
| wc.Test(WordCount) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.