Skip to content

Instantly share code, notes, and snippets.

@andrewalexander
Last active October 24, 2018 18:22
Show Gist options
  • Save andrewalexander/2d4a0fc50a1d22a000174c5f670cd64f to your computer and use it in GitHub Desktop.
Save andrewalexander/2d4a0fc50a1d22a000174c5f670cd64f to your computer and use it in GitHub Desktop.
mEmE fOrMaTtEr | a e s t h e t i c
package main
import (
"bytes"
"fmt"
"strings"
)
func main() {
guy := "this is why we can't have nice things"
fmt.Printf("spongeBoi(guy) = %s\n", spongeBoi(guy))
boi := "twelve factor apps"
fmt.Printf("aestheticeBoi(boi) = %+v\n", aestheticeBoi(boi))
}
func spongeBoi(p string) string {
var buf bytes.Buffer
lower := true
ps := strings.Split(p, "")
for _, s := range ps {
if lower {
buf.Write([]byte(strings.ToLower(s)))
lower = false
} else {
buf.Write([]byte(strings.ToUpper(s)))
lower = true
}
}
return buf.String()
}
func aestheticeBoi(p string) string {
var buf bytes.Buffer
ps := strings.Split(strings.TrimSpace(p), "")
for _, s := range ps {
buf.Write([]byte(strings.ToLower(s)))
buf.Write([]byte(" "))
}
return buf.String()
}
$ go run bois.go
spongeBoi(guy) = tHiS Is wHy wE CaN'T HaVe nIcE ThInGs
aestheticeBoi(boi) = t w e l v e f a c t o r a p p s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment