Skip to content

Commit

Permalink
Merge pull request #99 from LaunchCodeEducation/assignment-2-patches
Browse files Browse the repository at this point in the history
updates to task 3 and task4
  • Loading branch information
jwoolbright23 authored May 1, 2024
2 parents e012fa8 + 6debaed commit 62d509e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
40 changes: 20 additions & 20 deletions content/assignments/scrabble-scorer/object-transform/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ draft: false
weight: 4
originalAuthor: Sally Steuterman # to be set by page creator
originalAuthorGitHub: gildedgardenia # to be set by page creator
reviewer: Rob Thomas
reviewerGitHub: icre8FreeCode
reviewer: John Woolbright
reviewerGitHub: jwoolbright23
lastEditor: # update any time edits are made after review
lastEditorGitHub: # update any time edits are made after review
lastMod: # UPDATE ANY TIME CHANGES ARE MADE
Expand All @@ -24,28 +24,28 @@ lastMod: # UPDATE ANY TIME CHANGES ARE MADE
relevant section in the
`Objects and Math` chapter.
1. To access the letter arrays within `oldPointStructure`, use bracket
notation (`oldPointStructure['key']`).
notation (`oldPointStructure[key]`).
1. To access a particular element within a letter array, add a second set of
brackets (`oldPointStructure['key'][index]`), or assign the array to a
brackets (`oldPointStructure[key][index]`), or assign the array to a
variable and use `variableName[index]`.

```js {linenos=table}
console.log("Letters with score '4':", oldPointStructure['4']);
console.log("3rd letter within the key '4' array:", oldPointStructure['4'][2]);
console.log("Letters with score '4':", oldPointStructure[4]);
console.log("3rd letter within the key '4' array:", oldPointStructure[4][2]);

let letters = oldPointStructure['8'];
console.log("Letters with score '8':", letters);
console.log("2nd letter within the key '8' array:", letters[1]);
let letters = oldPointStructure[8];
console.log("Letters with score '8':", letters);
console.log("2nd letter within the key '8' array:", letters[1]);
```

**Console Output**

```console
Letters with score '4': [ 'F', 'H', 'V', 'W', 'Y' ]
3rd letter within the key '4' array: V
Letters with score '4': [ 'F', 'H', 'V', 'W', 'Y' ]
3rd letter within the key '4' array: V
Letters with score '8': [ 'J', 'X' ]
2nd letter within the key '8' array: X
Letters with score '8': [ 'J', 'X' ]
2nd letter within the key '8' array: X
```
{{% /notice %}}

Expand All @@ -59,13 +59,13 @@ lastMod: # UPDATE ANY TIME CHANGES ARE MADE
Hard-coding the `newPointStructure` object literal like this:

```js
let newPointStructure =
{
a:1,
b: 1,
c: 1,
etc ...
}
let newPointStructure =
{
a:1,
b: 1,
c: 1,
etc ...
}
```

won't pass. And you'll lose an opportunity to practice this skill.
Expand Down
46 changes: 23 additions & 23 deletions content/assignments/scrabble-scorer/scoring-transform/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ point value equal to the key. For example, `'A'` and `'R'` are worth 1,

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
inside the array paired with that key. *This search within a search is
inefficient*.

{{% notice green "Tip" "rocket" %}}
Think about this for a second. The scoring action takes in letters in a word as input
and outputs numerical point values.

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.
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.

{{% /notice %}}

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.

{{% notice blue Note "rocket" %}}
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!
{{% /notice %}}

Examples of the new key storage:

1. `a` is worth `1`
Expand All @@ -63,23 +65,21 @@ In `newPointStructure`, the letters themselves are keys, so a *single* search
will identify a point value.

{{% notice blue "Example" "rocket" %}}
Example of `newPointStructure` object usage.

Example of ``newPointStructure`` object usage.

```js
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**
```js
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
Scrabble scoring values for
letter a: 1
letter j: 8
letter z: 10
```
**Console Output**

```console
Scrabble scoring values for
letter a: 1
letter j: 8
letter z: 10
```
{{% /notice %}}

0 comments on commit 62d509e

Please sign in to comment.