-
-
Notifications
You must be signed in to change notification settings - Fork 398
London | 26-ITP-May | Hugh Mills | Sprint 3 | 2. practice tdd #1607
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
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,13 @@ | ||
| // function countChar(stringOfCharacters, findCharacter) { | ||
| // return 5 | ||
| // } | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let countChar = 0; | ||
| for (let stringNum = 0; stringNum < stringOfCharacters.length; stringNum++) { | ||
| if (findCharacter === stringOfCharacters[stringNum]){ | ||
| countChar++ | ||
| } | ||
| } | ||
| return countChar | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,29 @@ test("should count multiple occurrences of a character", () => { | |
| expect(count).toEqual(5); | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character", () => { | ||
| const str = "aaa aa"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(5); | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character with random characters", () => { | ||
| const str = "ajhyabhaakaka"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(6); | ||
| }) | ||
|
|
||
|
Comment on lines
+20
to
+33
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. The two cases looks quite similar, they both have random characters in the middle of |
||
| // Scenario: No Occurrences | ||
| // Given the input string `str`, | ||
| // And a character `char` that does not exist within `str`. | ||
| // When the function is called with these inputs, | ||
| // Then it should return 0, indicating that no occurrences of `char` were found. | ||
| test("should return 0 with no occurrence of the character", () => { | ||
| const str ="abcd"; | ||
| const char = "e"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(0); | ||
| }); | ||
|
Comment on lines
34
to
+44
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. There should be one more boundary case making |
||
|
|
||
|
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. I think the question requires to also handle 2nd and 3rd etc. Since the question itself may not be quite clear about that, you may clarify in slack channel. Thanks. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| // function getOrdinalNumber(num) { | ||
| // return "1st"; | ||
| // } | ||
|
|
||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| let text = num.toString(); | ||
| if (text === "11") { | ||
| return (text + "th"); | ||
| } | ||
| return (text + "st"); | ||
| } | ||
|
|
||
| // getOrdinalNumber(1)).toEqual("1st") | ||
| 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. if the question requires to also handle 2nd and 3rd etc, then there will be more test cases. |
Uh oh!
There was an error while loading. Please reload this page.
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.
semicolon missing in line 8 and line 11.