exalysis icon indicating copy to clipboard operation
exalysis copied to clipboard

scrabble: false positive 'LoopRuneNotByte' suggestion

Open bitfield opened this issue 6 years ago • 0 comments

Solution 59997d1a390d44568ad4664a7ea13d9e produces this suggestion:

Iterating over a string produces runes. A rune represents a Unicode character and can consist of multiple bytes. Try using runes instead of bytes.

But the solution does use runes:

// Package scrabble provides functions to play the game scrabble.
package scrabble

import "strings"

// Score takes a string and returns its scrabble score as an integer.
func Score(word string) int {
	scores := map[string]int{
		"aeioulnrst": 1,
		"dg":         2,
		"bcmp":       3,
		"fhvwy":      4,
		"k":          5,
		"jx":         8,
		"qz":         10,
	}

	var ret int

	word = strings.ToLower(word)

	for _, j := range word {
		for k := range scores {
			if strings.ContainsRune(k, j) {
				ret += scores[k]
			}
		}
	}

	return ret
}

bitfield avatar Mar 10 '19 10:03 bitfield