Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 922f26ae31 | |||
|
|
54faccb7fd |
@ -8,6 +8,8 @@ func printingExamples() {
|
||||
age := 69
|
||||
name := "Joe"
|
||||
|
||||
Divider("printing")
|
||||
|
||||
//Print
|
||||
fmt.Print("hello, ") // does NOT add a new line
|
||||
fmt.Print("world! \n") // add new line manually
|
||||
@ -37,7 +39,7 @@ func dataTypesExamples() {
|
||||
|
||||
// Date Types Doc https://go.dev/ref/spec#Types
|
||||
|
||||
fmt.Println("-------------------------STRINGS-------------------------")
|
||||
Divider("strings")
|
||||
// String docs https://go.dev/ref/spec#String_types
|
||||
|
||||
// Three ways to initialize a variable
|
||||
@ -60,7 +62,7 @@ func dataTypesExamples() {
|
||||
|
||||
// Numeric data types doc https://go.dev/ref/spec#Numeric_types
|
||||
|
||||
fmt.Println("-------------------------INTS-------------------------")
|
||||
Divider("ints")
|
||||
|
||||
// ints
|
||||
var ageOne int = 20
|
||||
@ -88,7 +90,7 @@ func dataTypesExamples() {
|
||||
|
||||
fmt.Println(posNumOne, posNumTwo, posNumThree, posNumFour)
|
||||
|
||||
fmt.Println("-------------------------FLOATS-------------------------")
|
||||
Divider("floats")
|
||||
|
||||
// decimal values default to float64
|
||||
var floatOne float32 = 25.98
|
||||
|
||||
74
daytwo.go
Normal file
74
daytwo.go
Normal file
@ -0,0 +1,74 @@
|
||||
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
10
goofin.go
@ -1,10 +0,0 @@
|
||||
package main
|
||||
|
||||
func divider(divider string) {
|
||||
endString := ""
|
||||
totalLength := 50
|
||||
length := len(divider)
|
||||
|
||||
//TODO make this return a fixed size divider!
|
||||
|
||||
}
|
||||
2
install-go.sh
Normal file
2
install-go.sh
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
69
main.go
69
main.go
@ -1,74 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
_ "fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
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
|
||||
|
||||
Divider("divided")
|
||||
}
|
||||
27
utils.go
Normal file
27
utils.go
Normal file
@ -0,0 +1,27 @@
|
||||
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