-
Notifications
You must be signed in to change notification settings - Fork 3
Fix #34 - https://tour.golang.org/moretypes/24 #37
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
AlMishbah
wants to merge
24
commits into
pondok-programmer:master
Choose a base branch
from
AlMishbah: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
24 commits
Select commit
Hold shift + click to select a range
2c3a24a
Fix #34 - https://tour.golang.org/moretypes/1
AlMishbah ca01dcd
Fix #34 - https://tour.golang.org/moretypes/2
AlMishbah ae68c37
Fix #34 - https://tour.golang.org/moretypes/3
AlMishbah 66322a3
Fix #34 - https://tour.golang.org/moretypes/4
AlMishbah a5dc656
Fix #34 - https://tour.golang.org/moretypes/5
AlMishbah 12905ba
Fix #34 - https://tour.golang.org/moretypes/6
AlMishbah 85a79ba
Fix #34 - https://tour.golang.org/moretypes/7
AlMishbah 2d21fc4
Fix #34 - https://tour.golang.org/moretypes/8
AlMishbah 1526cd5
Fix #34 - https://tour.golang.org/moretypes/9
AlMishbah d2cb8b2
Fix #34 - https://tour.golang.org/moretypes/10
AlMishbah 7045a61
Fix #34 - https://tour.golang.org/moretypes/11
AlMishbah 3824c13
Fix #34 - https://tour.golang.org/moretypes/12
AlMishbah 12465cb
Fix #34 - https://tour.golang.org/moretypes/13
AlMishbah 137feb3
Fix #34 - https://tour.golang.org/moretypes/14
AlMishbah a9b909a
Fix #34 - https://tour.golang.org/moretypes/15
AlMishbah 4d26335
Fix #34 - https://tour.golang.org/moretypes/16
AlMishbah 8f0f2dd
Fix #34 - https://tour.golang.org/moretypes/17
AlMishbah b022bf1
Fix #34 - https://tour.golang.org/moretypes/18
AlMishbah a76fcdd
Fix #34 - https://tour.golang.org/moretypes/19
AlMishbah 0a5e305
Fix #34 - https://tour.golang.org/moretypes/20
AlMishbah 8d93cd7
Fix #34 - https://tour.golang.org/moretypes/21
AlMishbah 033e8b3
Fix #34 - https://tour.golang.org/moretypes/22
AlMishbah 54aa24e
Fix #34 - https://tour.golang.org/moretypes/24
AlMishbah c62f2cf
Fix #34 - https://tour.golang.org/moretypes/23
AlMishbah 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 |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ import "fmt" | |
|
|
||
| func flowcontrol14() { | ||
| fmt.Println("You finished this lesson!") | ||
| fmt.Println() | ||
| } | ||
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 roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype1() { | ||
| i, j := 42, 2701 | ||
|
|
||
| p := &i | ||
| fmt.Println(*p) | ||
| *p = 21 | ||
| fmt.Println(i) | ||
|
|
||
| p = &j | ||
| *p = *p / 37 | ||
| fmt.Println(j) | ||
| } |
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 roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype10() { | ||
| s := []int{2, 3, 5, 7, 11, 13} | ||
|
|
||
| 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 roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype11() { | ||
| s := []int{2, 3, 5, 7, 11, 13} | ||
| 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,11 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype12() { | ||
| 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 roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype13() { | ||
| a := make([]int, 5) | ||
| PrintSlice("a", a) | ||
|
|
||
| b := make([]int, 0, 5) | ||
| PrintSlice("b", b) | ||
|
|
||
| c := b[:2] | ||
| PrintSlice("c", c) | ||
|
|
||
| d := c[2:5] | ||
| PrintSlice("d", d) | ||
| } | ||
|
|
||
| func PrintSlice(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 roihan | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| func moretype14() { | ||
| 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,21 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype15() { | ||
| var s []int | ||
| Printslice(s) | ||
|
|
||
| s = append(s, 0) | ||
| Printslice(s) | ||
|
|
||
| s = append(s, 1) | ||
| Printslice(s) | ||
|
|
||
| s = append(s, 2, 3, 4) | ||
| 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,11 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| var pos = []int{1, 2, 4, 8, 16, 32, 64, 128} | ||
|
|
||
| func moretype16() { | ||
| for i, v := range pos { | ||
| 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,13 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype17() { | ||
| por := make([]int, 10) | ||
| for i := range por { | ||
| por[i] = 1 << uint(i) | ||
| } | ||
| for _, value := range por { | ||
| 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,17 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| type vertex struct { | ||
| Lat, Long float64 | ||
| } | ||
|
|
||
| var m map[string]vertex | ||
|
|
||
| func moretype19() { | ||
| m = make(map[string]vertex) | ||
| m["Bell Labs"] = vertex{ | ||
| 40.648433, -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,12 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| type Vertex struct { | ||
| X int | ||
| Y int | ||
| } | ||
|
|
||
| func moretype2() { | ||
| fmt.Println(Vertex{1, 20}) | ||
| } |
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 roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| type Verte struct { | ||
| Lat, Long float64 | ||
| } | ||
|
|
||
| var ma = map[string]Verte{ | ||
| "Bell Labs": Verte{ | ||
| 40.648433, -74.39967, | ||
| }, | ||
| "Google": Verte{ | ||
| 37.42202, -122.08408, | ||
| }, | ||
| } | ||
|
|
||
| func moretype20() { | ||
| fmt.Println(ma) | ||
| } |
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 roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| type literals struct { | ||
| Lat, Long float64 | ||
| } | ||
|
|
||
| var mp = map[string]literals{ | ||
| "Bell Labs": {40.68433, -74.39967}, | ||
| "Google": {37.42202, -122.08408}, | ||
| } | ||
|
|
||
| func moretype21() { | ||
| fmt.Println(mp) | ||
| } |
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 roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype22() { | ||
| m := make(map[string]int) | ||
|
|
||
| m["Answer"] = 42 | ||
| fmt.Println("The value:", m["Answer"]) | ||
|
|
||
| m["Answer"] = 48 | ||
| fmt.Println("The value:", m["Answer"]) | ||
|
|
||
| delete(m, "Answer") | ||
| fmt.Println("The value:", m["Answer"]) | ||
|
|
||
| v, ok := m["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,11 @@ | ||
| package roihan | ||
|
|
||
| import "golang.org/x/tour/wc" | ||
|
|
||
| func WordCount(s string) map[string]int { | ||
| return map[string]int{"x": 1} | ||
| } | ||
|
|
||
| func moretype23() { | ||
| 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,20 @@ | ||
| package roihan | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "math" | ||
| ) | ||
|
|
||
| func compute(fn func(float64, float64) float64) float64 { | ||
| return fn(3, 4) | ||
| } | ||
|
|
||
| func moretype24() { | ||
| 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,14 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| type moretype struct { | ||
| X int | ||
| Y int | ||
| } | ||
|
|
||
| func moretype3() { | ||
| v := Vertex{1, 2} | ||
| v.X = 4 | ||
| fmt.Println(v.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,15 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| type Moretype struct { | ||
| X int | ||
| Y int | ||
| } | ||
|
|
||
| func moretype4() { | ||
| v := Moretype{1, 2} | ||
| p := &v | ||
| p.X = 1e9 | ||
| fmt.Println(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,18 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| type MoretypeVertex struct { | ||
| X, Y int | ||
| } | ||
|
|
||
| var ( | ||
| v1 = MoretypeVertex{1, 2} //Has type vertex | ||
| v2 = MoretypeVertex{X: 1} //Y:0 is implicit | ||
| v3 = MoretypeVertex{} //X:0 and Y:0 | ||
| p = &MoretypeVertex{1, 2} //Has type *Vertex | ||
| ) | ||
|
|
||
| func moretype5() { | ||
| fmt.Println(v1, p, v2, v3) | ||
| } |
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 roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype6() { | ||
| var a [2]string | ||
| a[0] = "Hello" | ||
| a[1] = "World" | ||
| fmt.Println(a[0], a[1]) | ||
| fmt.Println(a) | ||
|
|
||
| primes := [6]int{2, 3, 5, 11, 13} | ||
| fmt.Println(primes) | ||
| } |
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,10 @@ | ||
| package roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype7() { | ||
| primes := [6]int{2, 3, 5, 7, 11, 13} | ||
|
|
||
| var s []int = primes[1:4] | ||
| 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 roihan | ||
|
|
||
| import "fmt" | ||
|
|
||
| func moretype8() { | ||
| names := [3]string{ | ||
| "Roihan", | ||
| "Mishbahul", | ||
| "Anam", | ||
| } | ||
|
|
||
| fmt.Println(names) | ||
|
|
||
| a := names[0:2] | ||
| b := names[1:3] | ||
| fmt.Println(a, b) | ||
|
|
||
| b[0] = "XXX" | ||
| fmt.Println(a, b) | ||
| fmt.Println(names) | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ini logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testnya disini https://github.com/golang/tour/blob/8f38c9a8d074c1943ede6463d78b0d769331dd3e/wc/wc.go#L32