-
-
Notifications
You must be signed in to change notification settings - Fork 196
Sheffield | May-2025 | Declan Williams | Sprint-3 #623
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
be25f2c
4fa86db
d317d4f
dea34f8
952fd14
8cf3f58
6da0615
45209eb
37f345d
ed4eaf3
a0d4fcf
d32c392
e7f3d74
2e2d63c
900385e
67c92c2
60ed74f
bcdba1c
a16c211
aced4d1
0a913b0
de7632b
aa7b3ee
d2a8646
9798ed9
63a66e2
c89c3b8
2b44bf7
df5287d
1f02ed6
900db99
5d2265b
525641a
4f81c7d
d34ba19
dd38ca5
5798163
a8d9ac3
1a34fcf
c5d4342
e4b3cf0
885b7d5
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,7 +1,16 @@ | ||
function getAngleType(angle) { | ||
if (typeof angle !== "number" || angle <= 0 || angle > 360) return "Invalid angle"; | ||
|
||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
|
||
if (angle < 90) | ||
return "Acute angle"; | ||
if ((angle > 90) && (angle < 180)) | ||
return "Obtuse angle"; | ||
if (angle === 180) | ||
return "Straight angle"; | ||
if ((angle > 180) && (angle < 360)) | ||
return "Reflex angle"; | ||
} | ||
Comment on lines
+6
to
14
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 function can return Note: the spec fails to mention angles <= 0 are not "Acute angle". 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. addressed the problem about returning undefined for some angle values and to handle invalid inputs explicitly, I’ve added this validation check to return Invalid angle in these cases |
||
|
||
|
||
|
@@ -10,7 +19,6 @@ function getAngleType(angle) { | |
|
||
|
||
|
||
|
||
// Don't get bogged down in this detail | ||
// Jest uses CommonJS module syntax by default as it's quite old | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (denominator === 0) return false; // avoid division by zero | ||
return Math.abs(numerator) < Math.abs(denominator); | ||
Comment on lines
+2
to
+3
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. The condition at line 3 could also take case of cases where denominator is 0. |
||
} | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
var rank = card.slice(0, -1); // get the rank of the card by removing the last character. (the suit is the last character) | ||
if (rank === "A") return 11; // this checks for Aces | ||
// Handle Number Cards (2-9) | ||
if (rank === "2") return 2; // this checks for the twos | ||
if (rank === "3") return 3; // this checks for the threes | ||
if (rank === "4") return 4; // this checks for the fours | ||
if (rank === "5") return 5; // this should check for fives | ||
if (rank === "6") return 6; // this checks for the sixes | ||
if (rank === "7") return 7; // this checks for the sevens | ||
if (rank === "8") return 8; // this checks for the eights | ||
if (rank === "9") return 9; // this checks for the nines | ||
// Handle Face Cards (J, Q, K) And 10's | ||
if (rank === "J") return 10; // this checks for Jacks | ||
if (rank === "Q") return 10; // this checks for Queens | ||
if (rank === "K") return 10; // this checks for Kings | ||
if (rank === "10") return 10; // this checks for Tens | ||
// if none of the above its an invalid card and throw an error | ||
throw new Error("Invalid card rank."); // this will throw an error if the card is not a valid rank | ||
} | ||
|
||
module.exports = getCardValue; |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,27 @@ | ||
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 "11, 12 ,13" to always end in "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; |
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.
This is good.
Since
NaN
is also of type "number", you could also consider rejectingNaN
.