code-society-25-2

Lesson 06: Statements and Variables (Slides)

Pre-work

Please review the following resources before lecture:

Homework

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 file to configure the correct homework version.
    # Example config for students assigned to homework "D".
    HW_VERSION=D
    
  2. Run the program to determine the expression you must implement.
    npm install
    npm run compile
    npm start
    
  3. Update the code in the expression_calculator.ts file.
  4. To check your work, you can run the application using the first command below and run the tests using the second one.
    npm start
    
  5. As usual, make sure that you format your code and run the check command before creating your pull request.
    npm run check
    
  6. You must only submit changes to the expression_calculator.ts and .env.test files 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:

Function Signature:

function isValidAlphaAbbreviation(word: string, abbr: string): boolean

Examples:

Example 1:

Input: word = "internationalization", abbr = "imzdn"
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: