-
-
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
02f9da3
1ca6ee1
642bcd8
5b95434
e1a210b
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 with spaces", () => { | ||
| const str = "eee ee e e"; | ||
| const char = "e"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual7; | ||
| }); | ||
|
|
||
| test("should count multiple occurrences of a character with random characters", () => { | ||
| const str = "ajhyabhaa kaak"; | ||
| const char = "a"; | ||
| const count = countChar(str, char); | ||
| expect(count).toEqual(6); | ||
| }) | ||
|
|
||
| // 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
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. wracked my brain for this one and hit a blank, and advice would be great |
||
|
|
||
|
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.
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. Will ask on there and if needed update the code with it. ^_^ |
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| function repeatStr() { | ||
| function repeatStr(str, count) { | ||
| let result = ""; | ||
| if (count < 0) { | ||
| throw new Error("cannot be negative number") | ||
| } | ||
|
|
||
| for (let i=0; i < count; i++) { | ||
| result = result + str | ||
| } | ||
| // 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"; | ||
| } | ||
| return result; | ||
|
|
||
| }; | ||
|
|
||
| module.exports = repeatStr; | ||
|
|
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.
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, done that fix