Skip to content

scrabble: false positive 'LoopRuneNotByte' suggestion #87

@bitfield

Description

@bitfield

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions