-
-
Notifications
You must be signed in to change notification settings - Fork 337
London | 25-ITP-Sep | Payman Issa Baiglu | sprint 3 | 2-practice-tdd #883
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 9 commits
92afa66
9e894a7
ded405e
a124398
e7d7fff
fbacf4a
3585be7
bbc996c
5ee3f6b
354b5ac
fdc1b1a
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 count = 0; | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| if (stringOfCharacters[i] === findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
| console.log(countChar("hello world!", "l")); | ||
|
|
||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const suffixes = ["th", "st", "nd", "rd"]; | ||
| const date = num % 100; | ||
|
|
||
| if (date >= 11 && date <= 13) { | ||
| return num + "th"; | ||
| } | ||
| const suffix = suffixes[(date % 10)] || "th"; | ||
| return num + suffix; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,27 @@ const getOrdinalNumber = require("./get-ordinal-number"); | |
| // When the number is 1, | ||
| // Then the function should return "1st" | ||
|
|
||
| test("should return '1st' for 1", () => { | ||
| test("append 'nd' to numbers ending in 1, except those ending in 11", () => { | ||
| expect(getOrdinalNumber(1)).toEqual("1st"); | ||
| expect( getOrdinalNumber(21) ).toEqual("21st"); | ||
| expect( getOrdinalNumber(131) ).toEqual("131st"); | ||
| }); | ||
|
|
||
| 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"); | ||
| }); | ||
| test("append 'rd' to numbers ending in 3, except those ending in 13", () => { | ||
| expect(getOrdinalNumber(3)).toEqual("3rd"); | ||
| expect( getOrdinalNumber(33) ).toEqual("33rd"); | ||
| expect( getOrdinalNumber(133) ).toEqual("133rd"); | ||
| }); | ||
| test("append 'th' to numbers ending in 4, except those ending in 14", () => { | ||
| expect(getOrdinalNumber(4)).toEqual("4th"); | ||
| expect( getOrdinalNumber(24) ).toEqual("24th"); | ||
| expect( getOrdinalNumber(134) ).toEqual("134th"); | ||
| }); | ||
| test("should return '11th' for 11", () => { | ||
| expect(getOrdinalNumber(11)).toEqual("11th"); | ||
| }); | ||
|
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. The tests on lines 11-26 are good. Can you improve the tests on 27-34?
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 tried to improve the tests on line 27-34. also added a test for other numbers. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,19 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str , count) { | ||
| if (count < 0) { | ||
| throw new Error("Count must be a non-negative integer"); | ||
| } | ||
|
Comment on lines
+2
to
+4
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. How would the caller distinguish the result of the following two function calls?
Both function calls return the same value.
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 see your point. I changed it so it throw error. |
||
| if (count === 0) { | ||
| return ""; | ||
| } | ||
|
|
||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
| result += str; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| console.log(repeat("hello", 2)); | ||
|
|
||
|
|
||
| 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.
Why named the variable
date? The last two digits do not represent a date.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 for pointing that out. yes you are absolutely right! I was in class yesterday and couldn't focus enough. I changed it to a proper Variable name.