-
-
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 2 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,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,23 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| } | ||
|
|
||
| let result; | ||
| let rem_100 = num % 100; | ||
| let rem_10 = num % 10; | ||
| if (rem_100 == 11 || rem_100 == 12 || rem_100 == 13){ | ||
| result = num.toString() + "th"; | ||
| } | ||
| else if (rem_10 == 1){ | ||
| result = num.toString() +"st"; | ||
| } | ||
| else if (rem_10 == 2){ | ||
| result = num.toString() + "nd"; | ||
| } | ||
| else if (rem_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,31 @@ 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. |
||
| test("append 'nd' to numbers ending in 2, except those ending in 12", () => { | ||
| expect( getOrdinalNumber(2) ).toEqual("2nd"); | ||
| expect( getOrdinalNumber(22) ).toEqual("22nd"); | ||
| expect( getOrdinalNumber(132) ).toEqual("132nd"); | ||
| }); | ||
|
||
| 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){ | ||
| throw new Error("Count must be positive number!"); | ||
| } | ||
| 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 naming them
lastDigitandlastTwoDigits(more human readable).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.