Skip to content

Commit 1c1ba03

Browse files
committed
Initial code
1 parent 506d082 commit 1c1ba03

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

main.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
sponge_case "sponge-case/sponge-case"
8+
)
9+
10+
func main() {
11+
if len(os.Args) == 2 {
12+
applyToArgs()
13+
} else {
14+
applyToStdin()
15+
}
16+
}
17+
18+
func applyToStdin() {
19+
scanner := bufio.NewScanner(os.Stdin)
20+
for scanner.Scan() {
21+
fmt.Println(sponge_case.ApplyStr(scanner.Text()))
22+
}
23+
if err := scanner.Err(); err != nil {
24+
fmt.Println(err)
25+
}
26+
}
27+
28+
func applyToArgs() {
29+
fmt.Println(sponge_case.ApplyStr(os.Args[1]))
30+
}

sponge-case/sponge-case.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package sponge_case
2+
3+
import (
4+
"math/rand"
5+
"unicode"
6+
)
7+
8+
func ApplyStr(in string) string {
9+
out := make([]rune, len(in))
10+
var newChar rune
11+
12+
for pos, char := range []rune(in) {
13+
toUpper := rand.Float32() > 0.5
14+
if toUpper {
15+
newChar = unicode.ToUpper(char)
16+
} else {
17+
newChar = unicode.ToLower(char)
18+
}
19+
out[pos] = newChar
20+
}
21+
22+
return string(out)
23+
}

sponge-case/sponge-case_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package sponge_case
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func TestApplyStr(t *testing.T) {
9+
fmt.Println(ApplyStr("Das ist wirklich nicht witzig!"))
10+
}

0 commit comments

Comments
 (0)