123456789101112131415161718192021222324252627282930313233343536373839 |
- package kata
- import "strings"
- func Reverse(s string) string {
- rs := []rune(s)
- for i, j := 0, len(rs)-1; i < j; i, j = i+1, j-1 {
- rs[i], rs[j] = rs[j], rs[i]
- }
- return string(rs)
- }
- const NL = "\n"
- // VertMirror reverses each line in the multiline string.
- func VertMirror(s string) string {
- ss := strings.Split(s, NL)
- rs := make([]string, len(ss))
- for i, row := range ss {
- rs[i] = Reverse(row)
- }
- rev := strings.Join(rs, NL)
- return rev
- }
- // HorMirror reverses the line order in the multiline strings.
- func HorMirror(s string) string {
- ss := strings.Split(s, NL)
- for i, j := 0, len(ss)-1; i < j; i, j = i+1, j-1 {
- ss[i], ss[j] = ss[j], ss[i]
- }
- return strings.Join(ss, NL)
- }
- type FParam func(string) string
- func Oper(f FParam, x string) string {
- return f(x)
- }
|