-
-
Notifications
You must be signed in to change notification settings - Fork 240
Glasgow | 25-ITP-Sep | Fares Bakhet | Sprint 3 | coursework/sprint-3-practice-tdd #757
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
6ab27fc
9c2b470
48dba8f
76de1ca
7323aba
80cde9a
bea3492
44f3ca1
c2a674b
7d3028f
1590eec
2478386
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 | ||
| function countChar(str, char) { | ||
| return str.split(char).length - 1; | ||
| } | ||
|
|
||
| module.exports = countChar; | ||
|
|
||
| console.log( | ||
| countChar( | ||
| "The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.", | ||
| "a" | ||
| ) | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,42 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| num = num.toString(); | ||
| if ( | ||
| num.slice(-2) === "11" || | ||
| num.slice(-2) === "12" || | ||
| num.slice(-2) === "13" | ||
| ) { | ||
| return num + "th"; | ||
| } else if (num.slice(-1) === "1") { | ||
| return num + "st"; | ||
| return num + "st"; | ||
| } else if (num.slice(-1) === "2") { | ||
| return num + "nd"; | ||
| } else if (num.slice(-1) === "3") { | ||
| return num + "rd"; | ||
| } else { | ||
| return num + "th"; | ||
| } | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; | ||
|
|
||
| console.log(getOrdinalNumber(1)); | ||
| console.log(getOrdinalNumber(2)); | ||
| console.log(getOrdinalNumber(3)); | ||
| console.log(getOrdinalNumber(4)); | ||
| console.log(getOrdinalNumber(5)); | ||
| console.log(getOrdinalNumber(6)); | ||
| console.log(getOrdinalNumber(7)); | ||
| console.log(getOrdinalNumber(8)); | ||
| console.log(getOrdinalNumber(9)); | ||
| console.log(getOrdinalNumber(10)); | ||
| console.log(getOrdinalNumber(11)); | ||
| console.log(getOrdinalNumber(12)); | ||
| console.log(getOrdinalNumber(13)); | ||
| console.log(getOrdinalNumber(21)); | ||
| console.log(getOrdinalNumber(22)); | ||
| console.log(getOrdinalNumber(23)); | ||
| console.log(getOrdinalNumber(101)); | ||
| console.log(getOrdinalNumber(111)); | ||
| console.log(getOrdinalNumber(112)); | ||
| console.log(getOrdinalNumber(113)); | ||
|
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 scenario coverage. Listing individual values, however, can quickly lead to an unmanageable number of test cases. For example, we can prepare a test for numbers 2, 22, 132, etc. as
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. @cjyuan, Done 🫡 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,16 @@ | ||
| function repeat() { | ||
| return "hellohellohello"; | ||
| const str = arguments[0]; | ||
| const count = arguments[1]; | ||
|
||
| if (count < 0) { | ||
| throw new Error("Count must be a non-negative integer"); | ||
| } | ||
| let result = ""; | ||
| for (let i = 0; i < count; i++) { | ||
| result += str; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| module.exports = repeat; | ||
|
|
||
| console.log(repeat("hello", 3)); | ||
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.
There is an unreachable statement (dead code).
Note: because of the
returnstatements, usingelseis optional.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.
@cjyuan, Found it 😅😅😅