diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/golang-united-school-homework-3-.iml b/.idea/golang-united-school-homework-3-.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/golang-united-school-homework-3-.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..85a861c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f993855 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module homework + +go 1.18 diff --git a/task01-arrays.go b/task01-arrays.go index b9cd9e9..89a6e1a 100644 --- a/task01-arrays.go +++ b/task01-arrays.go @@ -2,5 +2,13 @@ package homework func average(input [15]float32) (result float32) { //Place your code here - return + var res float32 + var n int + for i := 0; i < len(input); i++ { + if input[i] > 0 { + res += input[i] + n++ + } + } + return float32(res) / float32(n) } diff --git a/task02-slice.go b/task02-slice.go index 1db4004..2646746 100644 --- a/task02-slice.go +++ b/task02-slice.go @@ -2,5 +2,8 @@ package homework func reverse(input []int64) (result []int64) { //Place your code here - return + for i, j := 0, len(input)-1; i < j; i, j = i+1, j-1 { + input[i], input[j] = input[j], input[i] + } + return input } diff --git a/task03-map.go b/task03-map.go index 903e118..962b575 100644 --- a/task03-map.go +++ b/task03-map.go @@ -1,6 +1,23 @@ package homework +import ( + "sort" +) + func sortMapValues(input map[int]string) (result []string) { //Place your code here - return + outArr := []string{} + keys := make([]int, len(input)) + i := 0 + for k := range input { + keys[i] = k + i++ + } + sort.Ints(keys) + + for _, k := range keys { + outArr = append(outArr, input[k]) + } + + return outArr }