From a0f415b07bd9d26c006fafc4207a3efa17acc98a Mon Sep 17 00:00:00 2001 From: AndrejLoz Date: Sun, 19 Jun 2022 01:24:29 +0200 Subject: [PATCH 1/8] AllOk --- task01-arrays.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/task01-arrays.go b/task01-arrays.go index b9cd9e9..4530229 100644 --- a/task01-arrays.go +++ b/task01-arrays.go @@ -1,6 +1,18 @@ package homework +//Task 1: Arrays +//Implement function that returns an average value of array (sum / N) +//input -> [1,2,3,4,5,6] +//output -> 3.5 + func average(input [15]float32) (result float32) { - //Place your code here - return + var numUnits int = 1 + var sum float32 = 0 + for i := 0; i < len(input); i++ { + if input[i] > 0 { + sum += input[i] + numUnits += 1 + } + } + return sum / float32(numUnits) } From 635e5f509f79f934d0945b9740e14d1c1b6c8073 Mon Sep 17 00:00:00 2001 From: AndrejLoz Date: Sun, 19 Jun 2022 01:27:41 +0200 Subject: [PATCH 2/8] AllOk1 --- task01-arrays.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task01-arrays.go b/task01-arrays.go index 4530229..3808c05 100644 --- a/task01-arrays.go +++ b/task01-arrays.go @@ -6,7 +6,7 @@ package homework //output -> 3.5 func average(input [15]float32) (result float32) { - var numUnits int = 1 + var numUnits int = 0 var sum float32 = 0 for i := 0; i < len(input); i++ { if input[i] > 0 { From 86f019d9d6fc465286cdc0b55eeab8355dbe431d Mon Sep 17 00:00:00 2001 From: AndrejLoz Date: Sun, 19 Jun 2022 01:29:46 +0200 Subject: [PATCH 3/8] AllOk1 --- .vscode/launch.json | 27 +++++++++++++++++++++++++++ go.mod | 3 +++ package.json | 19 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 go.mod create mode 100644 package.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..c1af383 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ], + "name": "Launch Extension", + "outFiles": [ + "${workspaceFolder}/out/**/*.js" + ], + "preLaunchTask": "npm", + "request": "launch", + "type": "extensionHost" + }, + + { + "command": "npm start", + "name": "Run npm start", + "request": "launch", + "type": "node-terminal" + }, + ] +} \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ce668a8 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module homework + +go 1.17 diff --git a/package.json b/package.json new file mode 100644 index 0000000..f5b99dd --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "homework", + "version": "1.0.0", + "description": "- Clone the repo\r - run `go mod init homework`\r - run `go mod tidy`\r - Edit task files\r - it contains correct package name\r - follow comments placeholder", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/AndrejLoz/golang-united-school-homework-3-.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/AndrejLoz/golang-united-school-homework-3-/issues" + }, + "homepage": "https://github.com/AndrejLoz/golang-united-school-homework-3-#readme" +} From ed2198705a2fa368eae548b2498cbd7ac332dfae Mon Sep 17 00:00:00 2001 From: AndrejLoz Date: Mon, 20 Jun 2022 23:43:05 +0200 Subject: [PATCH 4/8] AllOk2 --- task01-arrays.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/task01-arrays.go b/task01-arrays.go index 3808c05..a75107a 100644 --- a/task01-arrays.go +++ b/task01-arrays.go @@ -4,14 +4,13 @@ package homework //Implement function that returns an average value of array (sum / N) //input -> [1,2,3,4,5,6] //output -> 3.5 - func average(input [15]float32) (result float32) { var numUnits int = 0 var sum float32 = 0 for i := 0; i < len(input); i++ { if input[i] > 0 { sum += input[i] - numUnits += 1 + numUnits++ } } return sum / float32(numUnits) From 4732f72aace0c032dcf62716b3a49a11f9d43603 Mon Sep 17 00:00:00 2001 From: AndrejLoz Date: Mon, 20 Jun 2022 23:45:54 +0200 Subject: [PATCH 5/8] AllOk2 --- .gitignore | 15 --------------- .vscode/launch.json | 27 --------------------------- go.mod | 2 +- homework.go | 11 +++++++++++ package.json | 19 ------------------- task02-slice.go | 5 +++++ 6 files changed, 17 insertions(+), 62 deletions(-) delete mode 100644 .gitignore delete mode 100644 .vscode/launch.json create mode 100644 homework.go delete mode 100644 package.json diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 66fd13c..0000000 --- a/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -# vendor/ diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index c1af383..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}" - ], - "name": "Launch Extension", - "outFiles": [ - "${workspaceFolder}/out/**/*.js" - ], - "preLaunchTask": "npm", - "request": "launch", - "type": "extensionHost" - }, - - { - "command": "npm start", - "name": "Run npm start", - "request": "launch", - "type": "node-terminal" - }, - ] -} \ No newline at end of file diff --git a/go.mod b/go.mod index ce668a8..f993855 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module homework -go 1.17 +go 1.18 diff --git a/homework.go b/homework.go new file mode 100644 index 0000000..71e8ead --- /dev/null +++ b/homework.go @@ -0,0 +1,11 @@ +package homework + +import ( + "fmt" +) + +func homework() { + var myArr = [15]float32{1, 2, 3, 4, 5, 6} + + fmt.Println(average(myArr)) +} diff --git a/package.json b/package.json deleted file mode 100644 index f5b99dd..0000000 --- a/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "homework", - "version": "1.0.0", - "description": "- Clone the repo\r - run `go mod init homework`\r - run `go mod tidy`\r - Edit task files\r - it contains correct package name\r - follow comments placeholder", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/AndrejLoz/golang-united-school-homework-3-.git" - }, - "author": "", - "license": "ISC", - "bugs": { - "url": "https://github.com/AndrejLoz/golang-united-school-homework-3-/issues" - }, - "homepage": "https://github.com/AndrejLoz/golang-united-school-homework-3-#readme" -} diff --git a/task02-slice.go b/task02-slice.go index 1db4004..aac0b17 100644 --- a/task02-slice.go +++ b/task02-slice.go @@ -1,5 +1,10 @@ package homework +// Task 2: Slices +// function that returns the copy of the original slice in reverse order. The type of elements is int64. +// Input -> (1, 2, 5, 15) +// Output -> (15, 5, 2, 1) + func reverse(input []int64) (result []int64) { //Place your code here return From c8ab271e0d302958296270e0b02d8d2795630cc4 Mon Sep 17 00:00:00 2001 From: AndrejLoz Date: Tue, 21 Jun 2022 23:42:04 +0200 Subject: [PATCH 6/8] AllOkEnd --- task01-arrays.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/task01-arrays.go b/task01-arrays.go index a75107a..4655575 100644 --- a/task01-arrays.go +++ b/task01-arrays.go @@ -1,9 +1,10 @@ package homework -//Task 1: Arrays -//Implement function that returns an average value of array (sum / N) -//input -> [1,2,3,4,5,6] -//output -> 3.5 +// Task 1: Arrays +// Implement function that returns an average value of array (sum / N) +// input -> [1,2,3,4,5,6] +// output -> 3.5 + func average(input [15]float32) (result float32) { var numUnits int = 0 var sum float32 = 0 From 0f17ea5e9a7705c80e47ca6ec0c2adabc0d154a4 Mon Sep 17 00:00:00 2001 From: AndrejLoz Date: Tue, 21 Jun 2022 23:43:14 +0200 Subject: [PATCH 7/8] AllOkEnd --- task02-slice.go | 6 ++++-- task03-map.go | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/task02-slice.go b/task02-slice.go index aac0b17..f550864 100644 --- a/task02-slice.go +++ b/task02-slice.go @@ -6,6 +6,8 @@ package homework // Output -> (15, 5, 2, 1) func reverse(input []int64) (result []int64) { - //Place your code here - return + for i := len(input) - 1; i >= 0; i-- { + result = append(result, input[i]) + } + return result } diff --git a/task03-map.go b/task03-map.go index 903e118..0ebd345 100644 --- a/task03-map.go +++ b/task03-map.go @@ -1,6 +1,23 @@ package homework +import "sort" + +// Task 3: Maps +// function that returns map values sorted in order of increasing keys. +// Input -> {2: "a", 0: "b", 1: "c"} +// Output -> ["b", "c", "a"] +// Input -> {10: "aa", 0: "bb", 500: "cc"} +// Output -> ["bb", "aa", "cc"] + func sortMapValues(input map[int]string) (result []string) { - //Place your code here - return + var newMap = make([]int, 0) + var newVal = make([]string, 0) + for k, _ := range input { + newMap = append(newMap, k) + } + sort.Ints(newMap) + for _, v := range newMap { + newVal = append(newVal, input[v]) + } + return newVal } From 6083e958927e6f15ed8c9fef3d3ceae85323e8ee Mon Sep 17 00:00:00 2001 From: AndrejLoz Date: Tue, 21 Jun 2022 23:52:44 +0200 Subject: [PATCH 8/8] =?UTF-8?q?=D0=A4=D0=B4=D0=B4=D0=A9=D0=BB=D0=A3=D1=82?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homework.go | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 homework.go diff --git a/homework.go b/homework.go deleted file mode 100644 index 71e8ead..0000000 --- a/homework.go +++ /dev/null @@ -1,11 +0,0 @@ -package homework - -import ( - "fmt" -) - -func homework() { - var myArr = [15]float32{1, 2, 3, 4, 5, 6} - - fmt.Println(average(myArr)) -}