Sha256: 72d51be58ff5bff57654e366e2a8e35bd5088a3df7480d20c1943850f263cdcc

Contents?: true

Size: 624 Bytes

Versions: 396

Compression:

Stored size: 624 Bytes

Contents

package counter

import "unicode"

// Correct implementation
type Impl4 struct {
	newlines, characters, letters int
	lastChar                      rune
}

func (c *Impl4) AddString(s string) {
	for _, char := range s {
		c.lastChar = char
		if char == '\n' {
			c.newlines++
		} else if unicode.IsLetter(char) {
			c.letters++
		}
		c.characters++
	}
}

func (c Impl4) Lines() int {
	switch {
	case c.characters == 0:
		return 0
	case c.lastChar == '\n':
		return c.newlines
	default:
		return c.newlines + 1
	}
}

func (c Impl4) Letters() int    { return c.letters }
func (c Impl4) Characters() int { return c.characters }

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.138 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.137 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.136 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.135 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.134 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.133 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.132 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.131 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.130 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.129 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.128 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.127 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.126 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.125 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.124 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.123 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.122 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.121 tracks/go/exercises/counter/impl4.go
trackler-2.2.1.120 tracks/go/exercises/counter/impl4.go