Tidying up
This commit is contained in:
parent
541982c248
commit
54faccb7fd
@ -8,6 +8,8 @@ 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
|
||||||
@ -37,7 +39,7 @@ func dataTypesExamples() {
|
|||||||
|
|
||||||
// Date Types Doc https://go.dev/ref/spec#Types
|
// Date Types Doc https://go.dev/ref/spec#Types
|
||||||
|
|
||||||
fmt.Println("-------------------------STRINGS-------------------------")
|
Divider("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
|
||||||
@ -60,7 +62,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
|
||||||
|
|
||||||
fmt.Println("-------------------------INTS-------------------------")
|
Divider("ints")
|
||||||
|
|
||||||
// ints
|
// ints
|
||||||
var ageOne int = 20
|
var ageOne int = 20
|
||||||
@ -88,7 +90,7 @@ func dataTypesExamples() {
|
|||||||
|
|
||||||
fmt.Println(posNumOne, posNumTwo, posNumThree, posNumFour)
|
fmt.Println(posNumOne, posNumTwo, posNumThree, posNumFour)
|
||||||
|
|
||||||
fmt.Println("-------------------------FLOATS-------------------------")
|
Divider("floats")
|
||||||
|
|
||||||
// decimal values default to float64
|
// decimal values default to float64
|
||||||
var floatOne float32 = 25.98
|
var floatOne float32 = 25.98
|
||||||
|
@ -6,9 +6,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func arraysAndSorting() {
|
||||||
|
|
||||||
fmt.Println("-------------------------ARRAYS-------------------------")
|
Divider("arrays")
|
||||||
|
|
||||||
// Arrays in GOLang start at 0!!!
|
// Arrays in GOLang start at 0!!!
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(rangeOne)
|
fmt.Println(rangeOne)
|
||||||
|
|
||||||
fmt.Println("-------------------------STANDARD-LIBRARY-------------------------")
|
Divider("standard library")
|
||||||
|
|
||||||
// strings package
|
// strings package
|
||||||
|
|
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!
|
|
||||||
|
|
||||||
}
|
|
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 i := 0; i < dashLength / 2; i++ {
|
||||||
|
sb.WriteString("-")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(sb.String())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user