Compare commits
No commits in common. "day-2" and "master" have entirely different histories.
@ -8,8 +8,6 @@ func printingExamples() {
|
|||||||
age := 69
|
age := 69
|
||||||
name := "Joe"
|
name := "Joe"
|
||||||
|
|
||||||
Divider("printing")
|
|
||||||
|
|
||||||
//Print
|
//Print
|
||||||
fmt.Print("hello, ") // does NOT add a new line
|
fmt.Print("hello, ") // does NOT add a new line
|
||||||
fmt.Print("world! \n") // add new line manually
|
fmt.Print("world! \n") // add new line manually
|
||||||
@ -39,7 +37,7 @@ func dataTypesExamples() {
|
|||||||
|
|
||||||
// Date Types Doc https://go.dev/ref/spec#Types
|
// Date Types Doc https://go.dev/ref/spec#Types
|
||||||
|
|
||||||
Divider("strings")
|
fmt.Println("-------------------------STRINGS-------------------------")
|
||||||
// String docs https://go.dev/ref/spec#String_types
|
// String docs https://go.dev/ref/spec#String_types
|
||||||
|
|
||||||
// Three ways to initialize a variable
|
// Three ways to initialize a variable
|
||||||
@ -62,7 +60,7 @@ func dataTypesExamples() {
|
|||||||
|
|
||||||
// Numeric data types doc https://go.dev/ref/spec#Numeric_types
|
// Numeric data types doc https://go.dev/ref/spec#Numeric_types
|
||||||
|
|
||||||
Divider("ints")
|
fmt.Println("-------------------------INTS-------------------------")
|
||||||
|
|
||||||
// ints
|
// ints
|
||||||
var ageOne int = 20
|
var ageOne int = 20
|
||||||
@ -90,7 +88,7 @@ func dataTypesExamples() {
|
|||||||
|
|
||||||
fmt.Println(posNumOne, posNumTwo, posNumThree, posNumFour)
|
fmt.Println(posNumOne, posNumTwo, posNumThree, posNumFour)
|
||||||
|
|
||||||
Divider("floats")
|
fmt.Println("-------------------------FLOATS-------------------------")
|
||||||
|
|
||||||
// decimal values default to float64
|
// decimal values default to float64
|
||||||
var floatOne float32 = 25.98
|
var floatOne float32 = 25.98
|
||||||
|
|||||||
74
daytwo.go
74
daytwo.go
@ -1,74 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func arraysAndSorting() {
|
|
||||||
|
|
||||||
Divider("arrays")
|
|
||||||
|
|
||||||
// Arrays in GOLang start at 0!!!
|
|
||||||
|
|
||||||
// Three ways to initialize arrays
|
|
||||||
// you can either define the length in the [x]type part
|
|
||||||
// or let it determine the amount based on the number of entries given
|
|
||||||
var ages [3]int = [3]int{16, 17, 18}
|
|
||||||
var moreAges = [3]int{21, 22, 23}
|
|
||||||
names := [4]string{"mario", "luigi", "peach", "yoshi"}
|
|
||||||
|
|
||||||
fmt.Println(ages, len(moreAges), names) // len() function gets the length or size of array
|
|
||||||
|
|
||||||
// slices (use arrays under the hood)
|
|
||||||
var scores = []int{100, 50, 60}
|
|
||||||
scores[2] = 25
|
|
||||||
scores = append(scores, 85)
|
|
||||||
|
|
||||||
fmt.Println(scores, len(scores))
|
|
||||||
|
|
||||||
// slice ranges
|
|
||||||
rangeOne := names[1:3]
|
|
||||||
|
|
||||||
fmt.Println(rangeOne)
|
|
||||||
|
|
||||||
Divider("standard library")
|
|
||||||
|
|
||||||
// strings package
|
|
||||||
|
|
||||||
greeting := "hello there"
|
|
||||||
fmt.Println(strings.Contains(greeting, "hello")) // strings.Contains returns a boolean value depending on if the passed value contains the second string
|
|
||||||
fmt.Println(strings.Contains(greeting, "Hello")) // This function IS case-sensitive
|
|
||||||
|
|
||||||
fmt.Println(strings.ReplaceAll(greeting, "hello", "hi")) // Replaces all instances of the passed string
|
|
||||||
fmt.Println("Original string value is", greeting) // the original value is unchanged
|
|
||||||
fmt.Println(strings.ToUpper(greeting)) // returns the passed string all uppercase
|
|
||||||
|
|
||||||
fmt.Println(strings.Index(greeting, "ll")) // returns the first found position of the passed string
|
|
||||||
|
|
||||||
fmt.Println(strings.Split(greeting, " ")) // splits first passed string into an array at each of the second passed variables instances
|
|
||||||
|
|
||||||
// sort package
|
|
||||||
|
|
||||||
otherAges := []int{45, 20, 35, 30, 75, 60, 50, 25}
|
|
||||||
|
|
||||||
sort.Ints(otherAges) // sorts given values AND stores it in the same variable
|
|
||||||
fmt.Println(otherAges)
|
|
||||||
|
|
||||||
index := sort.SearchInts(otherAges, 30) // gets the index of the passed value from the array first passed
|
|
||||||
secondIndex := sort.SearchInts(otherAges, 90) // if the value passed is not found in the array, it will return what position it WOULD be in
|
|
||||||
thirdIndex := sort.SearchInts(otherAges, 55)
|
|
||||||
fmt.Println(index)
|
|
||||||
fmt.Println(secondIndex)
|
|
||||||
fmt.Println(thirdIndex)
|
|
||||||
|
|
||||||
otherNames := []string{"mario", "luigi", "yoshi", "peach", "bowser"}
|
|
||||||
|
|
||||||
sort.Strings(otherNames)
|
|
||||||
fmt.Println(otherNames)
|
|
||||||
|
|
||||||
fmt.Println(sort.SearchStrings(otherNames, "bowser")) // gives the position of the passed string in the array if found
|
|
||||||
fmt.Println(sort.SearchStrings(otherNames, "waluigi")) // otherwise will return where it WOULD be
|
|
||||||
|
|
||||||
}
|
|
||||||
10
goofin.go
Normal file
10
goofin.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func divider(divider string) {
|
||||||
|
endString := ""
|
||||||
|
totalLength := 50
|
||||||
|
length := len(divider)
|
||||||
|
|
||||||
|
//TODO make this return a fixed size divider!
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,2 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
export PATH=$PATH:/usr/local/go/bin
|
|
||||||
69
main.go
69
main.go
@ -1,9 +1,74 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
Divider("divided")
|
|
||||||
|
fmt.Println("-------------------------ARRAYS-------------------------")
|
||||||
|
|
||||||
|
// Arrays in GOLang start at 0!!!
|
||||||
|
|
||||||
|
// Three ways to initialize arrays
|
||||||
|
// you can either define the length in the [x]type part
|
||||||
|
// or let it determine the amount based on the number of entries given
|
||||||
|
var ages [3]int = [3]int{16, 17, 18}
|
||||||
|
var moreAges = [3]int{21, 22, 23}
|
||||||
|
names := [4]string{"mario", "luigi", "peach", "yoshi"}
|
||||||
|
|
||||||
|
fmt.Println(ages, len(moreAges), names) // len() function gets the length or size of array
|
||||||
|
|
||||||
|
// slices (use arrays under the hood)
|
||||||
|
var scores = []int{100, 50, 60}
|
||||||
|
scores[2] = 25
|
||||||
|
scores = append(scores, 85)
|
||||||
|
|
||||||
|
fmt.Println(scores, len(scores))
|
||||||
|
|
||||||
|
// slice ranges
|
||||||
|
rangeOne := names[1:3]
|
||||||
|
|
||||||
|
fmt.Println(rangeOne)
|
||||||
|
|
||||||
|
fmt.Println("-------------------------STANDARD-LIBRARY-------------------------")
|
||||||
|
|
||||||
|
// strings package
|
||||||
|
|
||||||
|
greeting := "hello there"
|
||||||
|
fmt.Println(strings.Contains(greeting, "hello")) // strings.Contains returns a boolean value depending on if the passed value contains the second string
|
||||||
|
fmt.Println(strings.Contains(greeting, "Hello")) // This function IS case-sensitive
|
||||||
|
|
||||||
|
fmt.Println(strings.ReplaceAll(greeting, "hello", "hi")) // Replaces all instances of the passed string
|
||||||
|
fmt.Println("Original string value is", greeting) // the original value is unchanged
|
||||||
|
fmt.Println(strings.ToUpper(greeting)) // returns the passed string all uppercase
|
||||||
|
|
||||||
|
fmt.Println(strings.Index(greeting, "ll")) // returns the first found position of the passed string
|
||||||
|
|
||||||
|
fmt.Println(strings.Split(greeting, " ")) // splits first passed string into an array at each of the second passed variables instances
|
||||||
|
|
||||||
|
// sort package
|
||||||
|
|
||||||
|
otherAges := []int{45, 20, 35, 30, 75, 60, 50, 25}
|
||||||
|
|
||||||
|
sort.Ints(otherAges) // sorts given values AND stores it in the same variable
|
||||||
|
fmt.Println(otherAges)
|
||||||
|
|
||||||
|
index := sort.SearchInts(otherAges, 30) // gets the index of the passed value from the array first passed
|
||||||
|
secondIndex := sort.SearchInts(otherAges, 90) // if the value passed is not found in the array, it will return what position it WOULD be in
|
||||||
|
thirdIndex := sort.SearchInts(otherAges, 55)
|
||||||
|
fmt.Println(index)
|
||||||
|
fmt.Println(secondIndex)
|
||||||
|
fmt.Println(thirdIndex)
|
||||||
|
|
||||||
|
otherNames := []string{"mario", "luigi", "yoshi", "peach", "bowser"}
|
||||||
|
|
||||||
|
sort.Strings(otherNames)
|
||||||
|
fmt.Println(otherNames)
|
||||||
|
|
||||||
|
fmt.Println(sort.SearchStrings(otherNames, "bowser")) // gives the position of the passed string in the array if found
|
||||||
|
fmt.Println(sort.SearchStrings(otherNames, "waluigi")) // otherwise will return where it WOULD be
|
||||||
|
|
||||||
}
|
}
|
||||||
27
utils.go
27
utils.go
@ -1,27 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Divider(divider string) {
|
|
||||||
totalLength := 50
|
|
||||||
|
|
||||||
divUpper := strings.ToUpper(strings.ReplaceAll(divider, " ", "-"))
|
|
||||||
length := len(divider)
|
|
||||||
dashLength := totalLength - length
|
|
||||||
sb := strings.Builder{}
|
|
||||||
|
|
||||||
for i := 0; i < dashLength / 2; i++ {
|
|
||||||
sb.WriteString("-")
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.WriteString(divUpper)
|
|
||||||
|
|
||||||
for len(sb.String()) < totalLength {
|
|
||||||
sb.WriteString("-")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println(sb.String())
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user