-
-
Notifications
You must be signed in to change notification settings - Fork 259
Glasgow | 25-ITP-Sep | Hanna Mykytiuk | Sprint 3 | practice-tdd #814
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
Changes from 1 commit
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,12 @@ | ||
|
|
||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let total = 0; | ||
| for (let i=0; i < stringOfCharacters.length; i++){ | ||
| if (findCharacter == stringOfCharacters[i]){ | ||
| total++; | ||
| } | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| } | ||
|
|
||
| let result; | ||
| if (num % 100 == 11 || num % 100 == 12 || num % 100 == 13){ | ||
| result = num.toString() + "th"; | ||
| } | ||
| else if (num % 10 == 1){ | ||
| result = num.toString() +"st"; | ||
| } | ||
| else if (num % 10 == 2){ | ||
| result = num.toString() + "nd"; | ||
| } | ||
| else if (num % 10 == 3){ | ||
| result = num.toString() + "rd"; | ||
| } | ||
| else { | ||
| result = num.toString() + "th"; | ||
| } | ||
|
|
||
| return result | ||
| } | ||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,26 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| test("should return '1st' for 1", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| }); | ||
|
|
||
| test("should return '2nd' for 2", () => { | ||
| expect(getOrdinalNumber(2)).toEqual("2nd"); | ||
| }); | ||
|
|
||
| test("should return '3rd' for 3", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| }); | ||
|
|
||
| test("should return '4th' for 4", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| }); | ||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }); | ||
|
|
||
| test("should return '12th' for 12", () => { | ||
| expect(getOrdinalNumber(12)).toEqual("12th"); | ||
| }); | ||
|
|
||
| test("should return '13th' for 13", () => { | ||
| expect(getOrdinalNumber(13)).toEqual("13th"); | ||
| }); | ||
|
Comment on lines
16
to
45
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. To ensure thorough testing, we need broad scenarios that cover all possible cases. For example, we can prepare a test for numbers 2, 22, 132, etc. as Can you make the tests in this script more comprehensive?
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, I have add it. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,16 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
|
|
||
| if (count < 0){ | ||
| return null | ||
| } | ||
|
Comment on lines
3
to
5
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. This works. An alternative is to throw an exception.
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 advice, I have changed it. |
||
| else if (count == 0){ | ||
| return "" | ||
| } | ||
| let result = ""; | ||
| for ( let i=0; i<count; i++){ | ||
| result +=str | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| module.exports = repeat; | ||
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.
Could consider storing the calculated result in a variable first (and then reuse the calculated value) to improve performance.
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 have changed it.