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
19 changes: 19 additions & 0 deletions module-4/task-1/palindrome/palindrome.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package palindrome

import (
"unicode/utf8"
)

func IsPalindrome(s string) bool {
reversed := reverse(s)
if s != reversed {
return false
}
return true
}

func reverse(s string) string {
totalLength := len(s)
buffer := make([]byte, totalLength)
for i := 0; i < totalLength; {
r, size := utf8.DecodeRuneInString(s[i:])
i += size
utf8.EncodeRune(buffer[totalLength-i:], r)
}
return string(buffer)
}
2 changes: 1 addition & 1 deletion module-4/task-1/palindrome/palindrome_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ func TestIsPalindrome(t *testing.T) {
exp bool
}{
{in: "aa", exp: true},
{in: "mełłem", exp: true},
{in: "ab", exp: false},
{in: "aba", exp: true},
{in: "mełłem", exp: true},
{in: "Hello", exp: false},
}

Expand Down
7 changes: 7 additions & 0 deletions module-4/task-2/panic/panic.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package panic

import "fmt"

func iWillPanic() {
panic("something")
}

func catchPanic() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered: ", r)
}
}()
iWillPanic()
}