-
-
Notifications
You must be signed in to change notification settings - Fork 338
London | 26-ITP-Jan | Miriam Jorna | Sprint 3 | Practice TDD #1241
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 6 commits
d36de13
205610d
7d1faf5
5fb5bbf
8222fda
2256f87
0644d6f
99213f2
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,11 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| let count = 0; | ||
| for (const char of stringOfCharacters) { | ||
| if (char === findCharacter) { | ||
| count++; | ||
| } | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; | ||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,25 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| if (num === 0) { | ||
| return "0"; | ||
| } | ||
|
|
||
| const lastTwoDigits = num % 100; | ||
| const lastDigit = num % 10; | ||
|
|
||
| switch (true) { | ||
| case lastTwoDigits === 11: | ||
| case lastTwoDigits === 12: | ||
| case lastTwoDigits === 13: | ||
| return `${num}th`; | ||
| case lastDigit === 1: | ||
| return `${num}st`; | ||
| case lastDigit === 2: | ||
| return `${num}nd`; | ||
| case lastDigit === 3: | ||
| return `${num}rd`; | ||
| default: | ||
| return `${num}th`; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
| module.exports = getOrdinalNumber; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| if (count < 0) { | ||
| throw new Error("Negative counts are not valid"); | ||
| } | ||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
|
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. Don't you think if the count is 0, it should return the empty string early?
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. It was in that order because I followed the format of the task as given. Now changed into better order with the test for 0 first. 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. Oh, that is not what I meant. I mean, you should check if count === 0, then return an empty string before the for loop
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. Oh! Apologies for overlooking to include that and then not seeing what you meant when you pointed it out! |
||
| result += str; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| module.exports = repeatStr; | ||
| module.exports = repeatStr; | ||
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.
Well done!. This works, but I think it can be cleaner. Move the case check for lastTwoDigits to the original if statement you had. Then the switch statement will be for lastDigit.
switch(lastDigit) { case 1: return${num}st; }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.
Took me a moment to straighten that out but I believe it's done now. Thank you!