-
-
Notifications
You must be signed in to change notification settings - Fork 336
London | 26-ITP-Jan | Maryanne Mosonik | Sprint 3 | Practice-TDD #1069
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
d83cfa4
b39a033
86d8ca9
3175f13
bef7de6
8757e5a
3bb795f
cc879bb
6a8425e
f047e59
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,11 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| } | ||
| let count = 0; | ||
| for(let char of stringOfCharacters){ | ||
| if (char === findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const str = String(num); | ||
|
|
||
| const lastTwo = num % 100; | ||
|
|
||
| if (lastTwo === 11 || lastTwo === 12 || lastTwo === 13) { | ||
| return str + "th"; | ||
| } | ||
| const lastDigit = num % 10; | ||
| if (lastDigit === 1) { | ||
| return str + "st"; | ||
| } else if (lastDigit === 2) { | ||
| return str + "nd"; | ||
| } else if (lastDigit === 3) { | ||
| return str + "rd"; | ||
| } else { | ||
| return str + "th"; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| if (count < 0) { | ||
| throw new Error("Count must be a non-negative integer"); | ||
| } | ||
| return str.repeat(count); | ||
| } | ||
|
|
||
| module.exports = repeatStr; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,30 @@ test("should repeat the string count times", () => { | |
| // Given a target string `str` and a `count` equal to 1, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should return the original `str` without repetition. | ||
| test("should return the original string when count is 1", () => { | ||
| const str = "hello"; | ||
| const count = 1; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual("hello"); | ||
| }); | ||
|
|
||
| // Case: Handle count of 0: | ||
| // Given a target string `str` and a `count` equal to 0, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should return an empty string. | ||
| test("should return an empty string when count is 0", () => { | ||
| const str = "hello"; | ||
| const count = 0; | ||
| const repeatedStr = repeatStr(str, count); | ||
| expect(repeatedStr).toEqual(""); | ||
| }); | ||
|
|
||
| // Case: Handle negative count: | ||
| // Given a target string `str` and a negative integer `count`, | ||
| // When the repeatStr function is called with these inputs, | ||
| // Then it should throw an error, as negative counts are not valid. | ||
| test("should throw an error when count is negative", () => { | ||
| const str = "hello"; | ||
| const count = -1; | ||
| expect(() => repeatStr(str, count)).toThrow("Count must be a non-negative integer"); | ||
| }); | ||
|
Comment on lines
+45
to
+49
Contributor
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. Can your implementation pass this test?
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. Yes it would because it is specifically checking for a negative count, which is an error. @cjyuan Kindly check implemented corrections. Thank you for your help.
Contributor
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. Did you run the test script to find out if your function can pass the test or if the test is prepared correctly?
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. Apologies, just checked, it fails, forgot to add the word integer as the expected substring and received messages were different. |
||
Uh oh!
There was an error while loading. Please reload this page.