diff --git a/array-sorter/go.mod b/array-sorter/go.mod new file mode 100644 index 0000000..3d0b255 --- /dev/null +++ b/array-sorter/go.mod @@ -0,0 +1,3 @@ +module array-sorter + +go 1.21.6 diff --git a/array-sorter/main.go b/array-sorter/main.go new file mode 100644 index 0000000..b7a88ed --- /dev/null +++ b/array-sorter/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "os" + "strconv" +) + +var numArray = []float64{} +var numToAdd int +var err error + +func main() { + if len(os.Args) < 2 { + fmt.Println("[-] Not enough arguments") + os.Exit(1) + } + for i := 1; i < (len(os.Args)); i++ { + numToAdd, err = strconv.Atoi(os.Args[i]) + numArray = append(numArray, float64(numToAdd)) + } + + if err != nil { + panic(err) + } + + fmt.Println("RESULTS:") + fmt.Println(numArray) + + fmt.Printf("\nSORTED RESULTS:\n") + sortedArray := sorter(numArray) + fmt.Printf("%v\n", sortedArray) +} + +func sorter(arr []float64) (orderedArr []float64) { + if len(arr) == 0 { + return nil + } + for i := 0; i < len(arr); i++ { + for _, v := range arr { + orderedArr = append(orderedArr, v) + } + } + return +}