Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #7

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .gitignore

This file was deleted.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module homework

go 1.18
16 changes: 14 additions & 2 deletions task01-arrays.go
Original file line number Diff line number Diff line change
@@ -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 = 0
var sum float32 = 0
for i := 0; i < len(input); i++ {
if input[i] > 0 {
sum += input[i]
numUnits++
}
}
return sum / float32(numUnits)
}
11 changes: 9 additions & 2 deletions task02-slice.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
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
for i := len(input) - 1; i >= 0; i-- {
result = append(result, input[i])
}
return result
}
21 changes: 19 additions & 2 deletions task03-map.go
Original file line number Diff line number Diff line change
@@ -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
}