DEV Community

Discussion on: Daily Challenge #205 - Consonant String Value

Collapse
 
emman27 profile image
Emmanuel Goh

Go, single-pass

package value

func ConsonantStringValue(s string) int {
    highest := 0
    total := 0
    for _, c := range s {
        if isVowel(c) {
            highest = max(highest, total)
            total = 0
            continue
        }
        total += toValue(c)
    }
    highest = max(highest, total)
    return highest
}

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}

func isVowel(c rune) bool {
    return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'
}

func toValue(c rune) int {
    return int(c) - 96
}