Repository navigation
London | ITP-26-May | Tomislav Dukez | Sprint 3 | Practice TDD #1445
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
base: main
Are you sure you want to change the base?
Changes from all commits
966e522
4699d42
1379d50
d86c3ed
602f4d6
1d5374d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| return stringOfCharacters.split("").filter((char) => char === findCharacter) | ||
| .length; | ||
| } | ||
|
|
||
| module.exports = countChar; |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fantastic test suite! Using Jest (test, expect) and covering clear scenarios like multiple occurrences and zero matches makes the code very robust. Great job |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fantastic implementation! Handling the special cases for 11, 12, and 13 along with robust input validation makes this code exceptionally reliable. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,24 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| // check if the input is not a number, not an integer, or if it's negative | ||
| if (typeof num !== "number" || !Number.isInteger(num) || num < 0) { | ||
|
tomdu3 marked this conversation as resolved.
|
||
| throw new Error("Invalid input: number must be a non-negative integer"); | ||
|
tomdu3 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| if (num % 100 >= 11 && num % 100 <= 13) { | ||
| // check for numbers ending with 11, 12, or 13 | ||
| return num + "th"; | ||
| } else if (num % 10 === 1) { | ||
| // check for numbers ending with 1 (but not 11) | ||
| return num + "st"; | ||
| } else if (num % 10 === 2) { | ||
| // check for numbers ending with 2 (but not 12) | ||
| return num + "nd"; | ||
| } else if (num % 10 === 3) { | ||
| // check for numbers ending with 3 (but not 13) | ||
| return num + "rd"; | ||
| } | ||
| // For all other numbers, append "th" | ||
| return num + "th"; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fantastic test suite! Grouping tests into meaningful categories (such as special endings, edge cases, negative numbers, and non-number inputs) provides exceptional test coverage. Great work |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fantastic recursive implementation! Avoiding String.prototype.repeat and using recursion to build the string while properly handling validation and edge cases is brilliant. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| function repeatStr() { | ||
| function repeatStr(stringOfCharacters, count) { | ||
| // Your implementation of this function must *not* call String.prototype.repeat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat). | ||
| // The goal is to re-implement that function, not to use it. | ||
| return "hellohellohello"; | ||
| if (count === 0) { | ||
| return ""; | ||
| } else if (count > 0) { | ||
| return repeatStr(stringOfCharacters, count - 1) + stringOfCharacters; | ||
| } | ||
| throw Error("Invalid input: count must be a non-negative integer"); | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fantastic test suite! Covering multiple repetitions, edge cases like 0 and 1, and negative input error handling ensures robust test coverage. |
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.
This is a wonderfully clean and expressive solution! Using array methods like
.split()and.filter()makes the logic very readable and easy to follow.Quick question: while this functional approach is great for readability, what happens if you pass a very large string? Can you think of an alternative way to count characters (like using a loop or
for...of) that avoids creating an intermediate array?