-
-
Notifications
You must be signed in to change notification settings - Fork 214
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 all commits
9d43b8b
8558783
ea7e00c
7b64029
f290799
aee6a4f
ae47b0c
4792575
3bd121a
c9b1c7d
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,22 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
let arrayOfCharacters = []; | ||
if (typeof stringOfCharacters === "string") { | ||
arrayOfCharacters = stringOfCharacters.split(""); | ||
} else if (Array.isArray(stringOfCharacters)) { | ||
arrayOfCharacters = stringOfCharacters; | ||
} else if (typeof stringOfCharacters === "number") { | ||
arrayOfCharacters = stringOfCharacters.toString().split(""); | ||
} else if (typeof stringOfCharacters === "object") { | ||
return 0; | ||
} | ||
|
||
let count = 0; | ||
for (let index = 0; index < arrayOfCharacters.length; index++) { | ||
if (arrayOfCharacters[index] === findCharacter) { | ||
count += 1; | ||
} | ||
} | ||
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,12 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
function repeat(str, count) { | ||
if ((Number(count) < 0) | (typeof str === "object")) { | ||
throw new Error("Invalid data value"); | ||
} | ||
try { | ||
return String(str).repeat(Number(count)); | ||
} catch (error) { | ||
throw new Error("Invalid data value"); | ||
} | ||
} | ||
|
||
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 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.