Task 3: Transform Scrabble Scoring

Currently, the software contains the data structure below for the traditional Scrabble scoring algorithm. Take a few moments to review how the oldPointStructure object relates a point value to a letter.

1
2
3
4
5
6
7
8
9
   const oldPointStructure = {
      1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'],
      2: ['D', 'G'],
      3: ['B', 'C', 'M', 'P'],
      4: ['F', 'H', 'V', 'W', 'Y'],
      5: ['K'],
      8: ['J', 'X'],
      10: ['Q', 'Z']
   };

The keys of oldPointStructure are the Scrabble points, and the values are arrays of letters. All letters in the array have the Scrabble point value equal to the key. For example, 'A' and 'R' are worth 1, 'K' is worth 5, and 'J' is worth 8.

To find the point value for a letter with the old format, the program must iterate over each key in oldPointStructure and then check if the letter is inefficient*.

Tip

Think about this for a second. The scoring action takes in letters in a word as input and outputs numerical point values.

We can improve our program by rewriting the data structure to better fit the action we want to take. Keep this idea in mind as you go on to code your own applications.

It would improve the performance of the program to create a newPointStructure object that has 26 keys, one for each letter. The value of each key will be the Scrabble point value.

Note

The newPointStructure object will be created and tested during Task 4. Below are examples of what the new object storage will look like, in addition to testing the new object itself. You will not be able to test the newPointStructure object until Task 4!

Examples of the new key storage:

  1. a is worth 1
  2. b is worth 3
  3. c is worth 3
  4. j is worth 8

In newPointStructure, the letters themselves are keys, so a single search will identify a point value.

Example

Example of newPointStructure object usage.

console.log("Scrabble scoring values for");
console.log("letter a: ", newPointStructure.a);
console.log("letter j: ", newPointStructure.j);
console.log("letter z: ", newPointStructure["z"]);

Console Output

Scrabble scoring values for
letter a:  1
letter j:  8
letter z:  10