DEV Community

Discussion on: Daily Challenge #8 - Scrabble Word Calculator

Collapse
 
margo1993 profile image
margo1993

Calculates only by letter points


import "strings"

var LETTER_POINTS = map[byte]int{
    'a': 1, 'b': 3, 'c': 3, 'd': 1, 'e': 1,
    'f': 4, 'g': 2, 'h': 4, 'i': 1, 'j': 8,
    'k': 5, 'l': 1, 'm': 3, 'n': 1, 'o': 1,
    'p': 3, 'q': 10, 'r': 1, 's': 1, 't': 1,
    'u': 1, 'v': 4, 'w': 4, 'x': 8, 'y': 4, 'z': 10,
}

func CalculateScrabblePoints(word string) int {
    points := 0

    if len(word) == 7 {
        return 50
    }

    lowerWord := strings.ToLower(word)

    for _, letter := range lowerWord {
        points += LETTER_POINTS[byte(letter)]
    }

    return points
}