Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 84 additions & 1 deletion lesson_06/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,87 @@ Please review the following resources before lecture:

## Homework

- TODO(anthonydmays): Add details on Monday
- [ ] Complete the [Expression Calculator](#expression-calculator) exercise.
- [ ] Read article entitled [3 Questions That Will Make You A Phenomenal Rubber Duck][article-link]
- [ ] Do pre-work for [lesson 07](/lesson_07/).

### Expression Calculator

For this assignment, you will need to implement the functions and logic required to calculate a mathematical expression. After implementing the `add`, `divide`, and `multiply` functions, you will combine these functions to compute the final result.

1. Update the [.env.test][env-file] file to configure the correct homework version.
```bash
# Example config for students assigned to homework "D".
HW_VERSION=D
```
2. Run the program to determine the expression you must implement.
```bash
npm install
npm run compile
npm start
```
1. Update the code in the [expression_calculator.ts][calculator-file] file.
2. To check your work, you can run the application using the first command below and run the tests using the second one.
```bash
npm start
```
1. As usual, make sure that you format your code and run the check command before creating your pull request.
```bash
npm run check
```
1. You must only submit changes to the `expression_calculator.ts` file to receive full credit.

### Stretch Assignment

Implement a function that validates whether a given alphabetic abbreviation matches a word using a special encoding system.

In this system, numbers in abbreviations are replaced by their corresponding alphabet letters:
- 'a' represents 1, 'b' represents 2, 'c' represents 3, ..., 'z' represents 26
- The abbreviation follows the same rules as standard abbreviations but uses letters instead of digits
- Letters cannot have leading zeros (e.g., no 'aa' for 01)
- Adjacent abbreviated substrings are not allowed
- Empty substrings cannot be abbreviated

**Function Signature:**
```typescript
function isValidAlphaAbbreviation(word: string, abbr: string): boolean
```

**Examples:**

Example 1:
```
Input: word = "internationalization", abbr = "irzdn"
Output: true
Explanation:
- "internationalization" can be abbreviated as "i m z d n"
- i + (m=13 chars) + z + (d=4 chars) + n
- i + nternationaliza + z + atio + n = "internationalization"
```

Example 2:
```
Input: word = "substitution", abbr = "sjn"
Output: true
Explanation:
- s + (j=10 chars) + n
- s + ubstitutio + n = "substitution"
```

**Invalid Examples:**
```
Input: word = "test", abbr = "ab"
Output: false
Explanation: Adjacent letters 'a' and 'b' would represent adjacent abbreviated substrings
```

**Constraints:**
- 1 ≤ word.length ≤ 25
- 1 ≤ abbr.length ≤ 15
- word consists of only lowercase English letters
- abbr consists of only lowercase English letters
- Letters representing numbers follow a=1, b=2, ..., z=26

[article-link]: https://blog.danslimmon.com/2024/01/18/3-questions-that-will-make-you-a-phenomenal-rubber-duck/
[calculator-file]: ./expression/src/expression_calculator.ts
[env-file]: ./expression/.env.test
8 changes: 8 additions & 0 deletions lesson_06/expression/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
1 change: 1 addition & 0 deletions lesson_06/expression/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HW_VERSION=your assigned version here
1 change: 1 addition & 0 deletions lesson_06/expression/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
3 changes: 3 additions & 0 deletions lesson_06/expression/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
1 change: 1 addition & 0 deletions lesson_06/expression/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
15 changes: 15 additions & 0 deletions lesson_06/expression/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintConfigPrettier from "eslint-config-prettier";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strict,
...tseslint.configs.stylistic,
eslintConfigPrettier,
{
ignores: ["build"],
},
);
11 changes: 11 additions & 0 deletions lesson_06/expression/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
export default {
testEnvironment: "node",
transform: {
"^.+.tsx?$": ["ts-jest", { useESM: true }],
},
moduleNameMapper: {
"^(\\.\\.?\\/.+)\\.js$": "$1",
},
extensionsToTreatAsEsm: [".ts"],
};
Loading
Loading