Repository navigation
North West | 26-ITP-Sep | Brian Yorachi | Sprint 2 | practice TDD #1706
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
37f8d79
de8c4b0
26e6bc9
8a70a6d
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,3 +1,11 @@ | ||
| export function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
|
|
||
| for (const character of stringOfCharacters) { | ||
| if (character === findCharacter) { | ||
| count += 1; | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,23 @@ | ||
| export function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastTwoDigits = num % 100; | ||
|
|
||
| if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { | ||
| return `${num}th`; | ||
| } | ||
|
|
||
| const lastDigit = num % 10; | ||
|
|
||
| if (lastDigit === 1) { | ||
| return `${num}st`; | ||
| } | ||
|
|
||
| if (lastDigit === 2) { | ||
| return `${num}nd`; | ||
| } | ||
|
|
||
| if (lastDigit === 3) { | ||
| return `${num}rd`; | ||
| } | ||
|
|
||
| return `${num}th`; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| export function repeatStr() { | ||
| export function repeatStr(str, 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) { | ||
| throw new Error("count must not be negative"); | ||
| } | ||
|
|
||
| let result = ""; | ||
|
|
||
| for (let i = 0; i < count; i += 1) { | ||
| result += str; | ||
| } | ||
|
|
||
| return result; | ||
| } |
|
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. Your test cases are correct. Just for you to think a little bit more, besides
Author
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. “Thanks for pointing that out! I added empty-string checks to each repeatStr test case.” |
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.
There is a special
strthat would give 0 anyway. Please add that test case as well. Thank you.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.
“Thanks! I added a test using an empty string as the input; it correctly returns 0.”