Sha256: e63a833e393813c086d72fffb2e6501eee69d0f7d8d76a7274c030ebd6a18b8b

Contents?: true

Size: 473 Bytes

Versions: 138

Compression:

Stored size: 473 Bytes

Contents

package igpay

import (
	"regexp"
	"strings"
)

var vowel = regexp.MustCompile(`^([aeiou]|y[^aeiou]|xr)[a-z]*`)
var cons = regexp.MustCompile(`^([^aeiou]?qu|[^aeiou]+)([a-z]*)`)

func PigLatin(s string) string {
	sw := strings.Fields(s)
	for i, w := range sw {
		l := strings.ToLower(w)
		if vowel.MatchString(l) {
			sw[i] = l + "ay"
		} else if x := cons.FindStringSubmatchIndex(l); x != nil {
			sw[i] = l[x[3]:] + l[:x[3]] + "ay"
		}
	}
	return strings.Join(sw, " ")
}

Version data entries

138 entries across 138 versions & 1 rubygems

Version Path
trackler-2.2.1.82 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.81 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.80 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.79 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.78 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.77 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.76 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.75 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.74 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.73 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.72 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.71 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.70 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.69 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.68 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.67 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.66 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.65 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.64 tracks/go/exercises/pig-latin/example.go
trackler-2.2.1.63 tracks/go/exercises/pig-latin/example.go