Skip to content
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
7 changes: 5 additions & 2 deletions Assignment/Assignment1/p1.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Output: -1

func DivideWhole(a int, b int) int {
// TODO: Your code here
return 0
if b != 0 {
return a / b
} else {
return -1
}
}

29 changes: 27 additions & 2 deletions Assignment/Assignment1/p2.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package Assignment1

import (
"strings"
"unicode"
)

/*
Clean up sentences. [WEIGHT = 1]

Expand Down Expand Up @@ -32,6 +37,26 @@ Explanation: Replace the : and , and then remove all trailing/leading spaces

func CleanUp(s string) string {
// TODO: Your code here
return ""
}
var cleanedStr strings.Builder
prevCharWasSpace := false
for _, r := range s {
if unicode.IsLetter(r) || unicode.IsNumber(r) || r == ' ' {
if r == ' ' {
if !prevCharWasSpace {
cleanedStr.WriteRune(r)
}
prevCharWasSpace = true
} else {
cleanedStr.WriteRune(r)
prevCharWasSpace = false
}
} else {
if !prevCharWasSpace {
cleanedStr.WriteRune(' ')
}
prevCharWasSpace = true
}
}

return strings.TrimSpace(cleanedStr.String())
}
15 changes: 13 additions & 2 deletions Assignment/Assignment1/p3.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ Explanation: All numbers are odd, so return 0

func EvenSum(nums []int) int {
// TODO: Your code here
return 0
}
result := 0

for _, i := range nums {
if i%2 == 0 {
result += i
}
}

if result != 0 {
return result
} else {
return 0
}
}