-
-
Notifications
You must be signed in to change notification settings - Fork 238
NW | 25-ITP-Sep | TzeMing Ho | Sprint 3 | coursework/sprint-3-practice-tdd #710
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 7 commits
9d43b8b
8558783
ea7e00c
7b64029
f290799
aee6a4f
ae47b0c
4792575
3bd121a
c9b1c7d
65578d2
589841c
fd74934
41893ad
4fc59b2
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,14 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| const arrayOfCharacters = stringOfCharacters.split(""); | ||
| let count = 0; | ||
| for (let index = 0; index < arrayOfCharacters.length; index++) { | ||
| if (arrayOfCharacters[index] === findCharacter) { | ||
| count += 1; | ||
| } | ||
| } | ||
| //console.log(arrayOfCharacters); | ||
| //console.log(count); | ||
| return count; | ||
| } | ||
|
|
||
| module.exports = countChar; |
|
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. Your test case covers the most basic cases - but can you think of some edge cases you should write tests for?
Writing tests to cover edge cases will protect your implementation from unexpected situations and make your code more robust. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,21 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const stringNum = String(num); | ||
| const paddedLast2Digit = stringNum.padStart(2, "0").slice(-2); | ||
| const numberValue = Number(paddedLast2Digit); | ||
|
|
||
| if (numberValue >= 11 && numberValue <= 13) { | ||
| return `${stringNum}th`; | ||
| } | ||
| if (stringNum.endsWith("1")) { | ||
| return `${stringNum}st`; | ||
| } | ||
| if (stringNum.endsWith("2")) { | ||
| return `${stringNum}nd`; | ||
| } | ||
| if (stringNum.endsWith("3")) { | ||
| return `${stringNum}rd`; | ||
| } | ||
| return `${stringNum}th`; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| function repeat(str, count) { | ||
| return str.repeat(count); | ||
| } | ||
|
|
||
| module.exports = repeat; |
|
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. You have written some good tests cases that cover the main cases. However, can you think of some edge cases that should be tested?
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. @TzeMingHo For this exercise, it says: This means that a number, boolean, null (basically anything not a string), should be considered invalid input. |
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.
It might have been a leftover from debugging, but console logs should be removed before submitting your PR.