示例#1
0
func findColors(guess, code string) int {
	uniqueGuess := unique.RemoveDuplicateLetters(guess)
	uniqueCode := unique.RemoveDuplicateLetters(code)

	var correctColors int
	for _, guessLetter := range uniqueGuess {
		for _, codeLetter := range uniqueCode {
			if guessLetter == codeLetter {
				correctColors++
			}
		}
	}

	return correctColors
}
示例#2
0
package unique_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/trayo/go_mastermind/unique"
)

var _ = Describe("removing duplicate elements", func() {
	It("can remove duplicate letters", func() {
		elements := "rygrygb"

		newElements := unique.RemoveDuplicateLetters(elements)

		Expect(newElements).To(Equal("rygb"))
	})

	It("can return an array of a unique letter", func() {
		elements := "rrrrrrr"

		newElements := unique.RemoveDuplicateLetters(elements)

		Expect(newElements).To(Equal("r"))
	})
})