-
-
Notifications
You must be signed in to change notification settings - Fork 269
Sheffield | 25-ITP-SEP | Declan Williams | Sprint 3 | Coursework #878
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 29 commits
32eef26
0709cbe
def5669
487694e
5fb6f95
876b8a1
801d5d8
7e6166b
dbf085f
a09a992
5f2aa2c
22f8e4a
f3f8b47
f08ec15
234e8b6
6a021e3
7455253
5e1196f
cc80d7e
ca08ca9
7dc44ec
5e720c8
252bfb9
3b7e322
809e11b
0b2a485
377b7db
096d45c
1200ba7
014b90e
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 |
|---|---|---|
|
|
@@ -7,7 +7,16 @@ test("should return true for a proper fraction", () => { | |
| }); | ||
|
|
||
| // Case 2: Identify Improper Fractions: | ||
| test("should return false for an improper fraction", () => { | ||
| expect(isProperFraction(5, 2)).toEqual(false); | ||
| }); | ||
|
|
||
| // Case 3: Identify Negative Fractions: | ||
| test("should return true for a negative proper fraction", () => { | ||
| expect(isproperFraction(-4, 7)).toEqual(true); | ||
| }); | ||
|
Comment on lines
+15
to
+17
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. Could consider introduce a test for negative improper fraction to make the test more complete.
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. have implemented the test for negative improper fractions. |
||
|
|
||
| // Case 4: Identify Equal Numerator and Denominator: | ||
| test ("should return false when numerator equals denominator", () => { | ||
| expect(isProperFraction(3, 3)).toEqual(false); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,18 @@ | ||
| function countChar(stringOfCharacters, findCharacter) { | ||
| return 5 | ||
| // start a count of 0 | ||
| let count = 0; | ||
|
|
||
| // check each of the characters in the string one by one. | ||
| for (let i = 0; i < stringOfCharacters.length; i++) { | ||
| // checks if the current characters matches the one were looking for in the string. | ||
| if (stringOfCharacters[i] === findCharacter) | ||
| // if it does, we increment the count by 1. | ||
| count = count + 1; | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
| console.log(countChar("aaaaa", "a")); // 5 | ||
| console.log(countChar("hello", "l")); // 2 | ||
|
|
||
| module.exports = countChar; | ||
| module.exports = countChar; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,26 @@ | ||
| function getOrdinalNumber(num) { | ||
| return "1st"; | ||
| const lastTwoDigits = num % 100; // gets the last two digits of the number because some like 11, 12, 13 are special cases. | ||
| const lastDigit= num % 10; // gets the last digit to decide if its going to be "St, Nd, Rd" | ||
|
|
||
| // handles special cases like "11,12,13" to always end in the "Th" | ||
| if (lastTwoDigits === 11 || lastTwoDigits === 12 || lastTwoDigits === 13){ | ||
| return num + "th"; | ||
| } | ||
| // will return "St" if the number ends in 1. | ||
| if (lastDigit === 1){ | ||
| return num + "st"; | ||
| } | ||
| // will return "Nd" if the number ends in 2. | ||
| if (lastDigit === 2){ | ||
| return num + "nd"; | ||
| } | ||
| // will return "Rd" if the number ends in 3. | ||
| if (lastDigit === 3){ | ||
| return num + "rd"; | ||
| } | ||
|
|
||
| // will return all numbers that end in 4, 5, 6, 7, 8, 9 with "Th". | ||
| return num + "th"; | ||
| } | ||
|
|
||
| module.exports = getOrdinalNumber; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,19 @@ | ||
| function repeatStr() { | ||
| return "hellohellohello"; | ||
| function repeatStr(str, count) { | ||
| // check if "count" is a negative number if so will throw new error | ||
| if (count < 0) { | ||
| throw new error("Count must be a positive number"); | ||
|
|
||
| //check if the is equal to zero | ||
| if (count === 0){ | ||
| return ""; // returns empty string if count is equal to zero | ||
| } | ||
| //check if the count is equals 1. | ||
| if (count === 1) { | ||
| //returns just the string as its not needed to be repeated | ||
| return str; | ||
| } | ||
| return str.repeat(count); // if the count is above two it repeat "count" number of times. | ||
| } | ||
| } | ||
|
|
||
| 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.
There is no "division by zero" needs to be prevented though.
Will the function still work equally well without this if statement?
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.
yes it would still work because it would return false implicitly with out the if-statement, as im currently explicitly looking for the error having the if-statement in.