-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from hegdeashwin/develop
Develop
- Loading branch information
Showing
9 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,38 @@ | ||
package main | ||
|
||
import "fmt"; | ||
|
||
func GetPrefix(name string, mustDel bool) (prefix string) { | ||
|
||
/** | ||
* Short hand way to declare and initialize map | ||
*/ | ||
prefixMap := map[string] string { | ||
"Ashwin": "Sr. Fullstack Engineer", | ||
"Kumar": "Sr. Engineering Manager", | ||
"Saju": "Sr. Solution Architect", | ||
"Ajay": "Sr. Solution Architect", // comma is needed here | ||
} | ||
|
||
if mustDel { | ||
delete(prefixMap, "Saju") | ||
} | ||
|
||
/** | ||
* Check if the value exist into the map or not. | ||
*/ | ||
if _, exists := prefixMap[name]; exists { | ||
return prefixMap[name] | ||
} else { | ||
return "dude" | ||
} | ||
|
||
} | ||
|
||
func main() { | ||
|
||
fmt.Println("What is Saju's role? He is " + GetPrefix("Saju", false)) | ||
|
||
fmt.Println("What is Saju's role? He is " + GetPrefix("Saju", true)) | ||
|
||
} |
This file contains 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,35 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
|
||
/** | ||
* Blank [] will declare a slices. | ||
* If you provide size like [5] will declare an array. | ||
*/ | ||
var employee []string | ||
|
||
/** | ||
* Initialize a slices with type, length and capacity. | ||
* length is required field. | ||
* | ||
* make([]string, length, [capacity]) | ||
*/ | ||
employee = make([]string, 3) | ||
|
||
employee[0] = "Ashwin" | ||
employee[1] = "Kumar" | ||
employee[2] = "Saju" | ||
|
||
fmt.Println("Slices: ", employee) | ||
|
||
/** | ||
* Appending into slices. | ||
*/ | ||
employee = append(employee, "Ajay") | ||
employee = append(employee, "Vinayak") | ||
|
||
fmt.Println("After appending: ", employee) | ||
|
||
} |
This file contains 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,23 @@ | ||
package main | ||
|
||
func main() { | ||
|
||
/** | ||
* Blank [] will declare a slices. | ||
* If you provide size like [5] will declare an array. | ||
*/ | ||
var employee []string | ||
|
||
/** | ||
* Initialize a slices with type, length and capacity. | ||
* length is required field. | ||
* | ||
* make([]string, length, [capacity]) | ||
*/ | ||
employee = make([]string, 3) | ||
|
||
employee[0] = "Ashwin" | ||
employee[1] = "Kumar" | ||
employee[2] = "Saju" | ||
// employee[3] = "Ajay" // This will throw an error `out of range` | ||
} |
This file contains 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,36 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
|
||
/** | ||
* Blank [] will declare a slices. | ||
* If you provide size like [5] will declare an array. | ||
*/ | ||
var employee []string | ||
|
||
/** | ||
* Initialize a slices with type, length and capacity. | ||
* length is required field. | ||
* | ||
* make([]string, length, [capacity]) | ||
*/ | ||
employee = make([]string, 6) | ||
|
||
employee[0] = "Ashwin" | ||
employee[1] = "Kumar" | ||
employee[2] = "Saju" | ||
employee[3] = "Ajay" | ||
employee[4] = "Vinayak" | ||
employee[5] = "Jerin" | ||
|
||
fmt.Println("Slices: ", employee) | ||
|
||
// 0:2 - include 0, 1 but excludes 2 | ||
// 4: - include last | ||
// ... - expanding slices | ||
employee = append(employee[0:2], employee[4:]...) | ||
|
||
fmt.Println("After Delete: ", employee) | ||
} |
This file contains 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 main | ||
|
||
func main() { | ||
|
||
/** | ||
* Short hand way to declare and initialize slices | ||
*/ | ||
employee := []string { | ||
"Ashwin", "Kumar", "Saju", "Ajay" | ||
} | ||
|
||
} |
This file contains 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,49 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
|
||
/** | ||
* Blank [] will declare a slices. | ||
* If you provide size like [5] will declare an array. | ||
*/ | ||
var employee []string | ||
|
||
/** | ||
* Initialize a slices with type, length and capacity. | ||
* length is required field. | ||
* | ||
* make([]string, length, [capacity]) | ||
*/ | ||
employee = make([]string, 7) | ||
|
||
employee[0] = "Ashwin" | ||
employee[1] = "Kumar" | ||
employee[2] = "Saju" | ||
employee[3] = "Ajay" | ||
employee[4] = "Jerin" | ||
employee[5] = "Vinayak" | ||
employee[6] = "Pavan" | ||
|
||
/** | ||
* Slices and updating slices | ||
*/ | ||
employee = employee[0:] | ||
fmt.Println("[0:]", employee) | ||
|
||
employee = employee[0:7] | ||
fmt.Println("[0:7]", employee) | ||
|
||
employee = employee[0:len(employee)] | ||
fmt.Println("[0:len(employee)]", employee) | ||
|
||
employee = employee[:4] | ||
fmt.Println("[0:4]", employee) | ||
|
||
employee = employee[0:4] | ||
fmt.Println("[:4]", employee) | ||
|
||
employee = employee[4:7] | ||
fmt.Println("[4:7]", employee) | ||
} |
Empty file.
Empty file.
Empty file.