Skip to content

Instantly share code, notes, and snippets.

@szemate
Last active March 17, 2022 17:56
Show Gist options
  • Save szemate/eff5a84688c3c706abe5509cfeb03932 to your computer and use it in GitHub Desktop.
Save szemate/eff5a84688c3c706abe5509cfeb03932 to your computer and use it in GitHub Desktop.
Scrabble Word Scores Exercise

Scrabble Word Scores Exercise

In this word game points are awarded based on the length of the word and the letters used. The user has to create a word from the letters in their hand. Their hand consists of 7 letters.

Could you create a function which returns the correct scores for the words played? The input is a list of words, and the output is an object where the keys are the words played and the values are the word points.

The score of the word is the sum of the points of all the letters multiplied by the number of letters in the word. If they use all 7 of their letters then they get a 50-point bonus.

The letter points are:

"a" : 1,
"b" : 3,
"c" : 3,
"d" : 2,
"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

Examples:

  • The word 'great' gives a score of 30. The sum of the letter values is 6 (g=2, r=1, e=1, a=1, t=1) and it is a 5-letter word, and 6*5=30.
  • The word 'jukebox' gives a score of 239. The sum of the letter values is 27 (j=8, u=1, k=5, e=1, b=3, o=1, x=8) and it is a 7-letter word therefore it gets the 50-point bonus, and 27*7+50=239.

Example input:

["great", "jukebox"]

Example output:

{
  great: 30,
  jukebox: 244
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment