-
Notifications
You must be signed in to change notification settings - Fork 29
Feature: adds Kerry Ferguson's lesson_06 stretch assignment #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
KerryFerguson04
wants to merge
2
commits into
code-differently:main
from
KerryFerguson04:feature/lesson_06/expression-stretch
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| HW_VERSION=your assigned version here | ||
| HW_VERSION=A |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # Stretch Assignment | ||
|
|
||
| ```typescript | ||
| /** | ||
| * 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=1, b=2, ..., z=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 | ||
| * | ||
| * @param word - The original word to match against (1-25 characters, lowercase English letters) | ||
| * @param abbr - The alphabetic abbreviation to validate (1-15 characters, lowercase English letters) | ||
| * @returns true if the abbreviation is valid for the given word, false otherwise | ||
| * | ||
| * @example | ||
| * // Example 1: Valid abbreviation | ||
| * isValidAlphaAbbreviation("internationalization", "irzdn") | ||
| * // Returns: true | ||
| * // Explanation: i + (r=18 chars) + z + (d=4 chars) + n = "internationalization" | ||
| */ | ||
|
|
||
| function isValidAlphaAbbreviation(word: string, abbr: string): boolean { | ||
| /** | ||
| * Hashmap mapping every letter to its numerical value in the encoding system. | ||
| * Used to convert letters to their corresponding skip counts. | ||
| * @type {Record<string, number>} | ||
| */ | ||
| const letterToNumberMap: Record<string, number> = { | ||
| a: 1, | ||
| b: 2, | ||
| c: 3, | ||
| d: 4, | ||
| e: 5, | ||
| f: 6, | ||
| g: 7, | ||
| h: 8, | ||
| i: 9, | ||
| j: 10, | ||
| k: 11, | ||
| l: 12, | ||
| m: 13, | ||
| n: 14, | ||
| o: 15, | ||
| p: 16, | ||
| q: 17, | ||
| r: 18, | ||
| s: 19, | ||
| t: 20, | ||
| u: 21, | ||
| v: 22, | ||
| w: 23, | ||
| x: 24, | ||
| y: 25, | ||
| z: 26, | ||
| }; | ||
|
|
||
| // Input validation: abbreviation cannot be longer than the original word | ||
| if (word.length < abbr.length) { | ||
| return false; // Abbreviation cannot be longer than the word | ||
| } | ||
|
|
||
| // Input validation: both strings must be non-empty | ||
| if (word.length == 0 || abbr.length == 0) { | ||
| return false; // Both word and abbreviation must be non-empty | ||
| } | ||
|
|
||
| let wordIndex = 0; // Current position in the original word | ||
|
|
||
| // Process each character in the abbreviation | ||
| for ( | ||
| let abbreviationIndex = 0; | ||
| abbreviationIndex < abbr.length; | ||
| abbreviationIndex++ | ||
| ) { | ||
| // Pattern: even indices are literal characters, odd indices are skip counts | ||
| if (abbreviationIndex % 2 == 0) { | ||
| // Even index: treat as a literal character that must match the word | ||
| if (abbr[abbreviationIndex] !== word[wordIndex]) { | ||
| return false; // Invalid character in abbreviation | ||
| } else { | ||
| wordIndex++; // Move to next character in word | ||
| } | ||
| } else { | ||
| // Odd index: treat as a letter representing a number of characters to skip | ||
| wordIndex += letterToNumberMap[abbr[abbreviationIndex]]; | ||
| } | ||
| } | ||
| // Verify that we've consumed the entire word (no extra characters left) | ||
| return wordIndex === word.length; // Ensure we have matched the entire word | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next time, consider converting the char code so that you don't have to use extra memory with a dictionary.