-
-
Notifications
You must be signed in to change notification settings - Fork 196
Sheffield | May-2025 | Hassan Osman | Sprint-3 #580
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 13 commits
9b98e48
1e65655
5634292
5d17a56
531b3ed
1472a6e
0286d78
5bd333e
3498122
33809e8
f8895ad
06411c8
489b22f
6284562
c4a2aca
7c4389d
499bcf1
34dd33f
784a678
0ec98ea
f7bfacf
8461178
16a010c
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,6 +1,10 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (numerator >= denominator) { | ||
return false; | ||
} else { | ||
return true; | ||
|
||
} | ||
} | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,42 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
switch(card) { | ||
case "A♠": | ||
case "A": | ||
return 11; | ||
break; | ||
case "2♠": | ||
return 2; | ||
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. A card can have one of four possible suits; the last character can also be a heart, club, or diamond. Your approach works great if you can extract the rank from the parameter first. |
||
break; | ||
case "3♠": | ||
return 3; | ||
break; | ||
case "4♠": | ||
return 4; | ||
break; | ||
case "5♠": | ||
return 5; | ||
break; | ||
case "6♠": | ||
return 6; | ||
break; | ||
case "7♠": | ||
return 7; | ||
break; | ||
case "8♠": | ||
return 8; | ||
break; | ||
case "9♠": | ||
return 9; | ||
break; | ||
case "10♠": | ||
case "J♠": | ||
case "K♠": | ||
case "Q♠": | ||
return 10; | ||
break; | ||
default: | ||
throw new Error("Invalid card rank"); | ||
|
||
} | ||
} | ||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,47 @@ const getCardValue = require("./3-get-card-value"); | |
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
test("should return 3 for 3♠ card", () => { | ||
const numberCards = getCardValue("3♠"); | ||
expect(numberCards).toEqual(3); | ||
}); | ||
|
||
test("should return 9 for 9♠", () => { | ||
const numberCards = getCardValue("9♠"); | ||
expect(numberCards).toEqual(9); | ||
}); | ||
|
||
|
||
|
||
// Case 3: Handle Face Cards (J, Q, K): | ||
test("should return 10 for K♠ card", () => { | ||
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. We could generalise this test to "should return 10 for face cards (J, Q, K)" and check all three ranks J, Q, K). Same for "all number cards". |
||
const faceCards = getCardValue("K♠"); | ||
expect(faceCards).toEqual(10); | ||
}); | ||
|
||
test("should return 10 for Q♠ card", () => { | ||
const faceCards = getCardValue("Q♠"); | ||
expect(faceCards).toEqual(10); | ||
}); | ||
|
||
// Case 4: Handle Ace (A): | ||
test("should return 11 for Ace", () => { | ||
const ace = getCardValue("A"); | ||
expect(ace).toEqual(11); | ||
}); | ||
|
||
// Case 5: Handle Invalid Cards: | ||
test("should throw Invalid card rank for invalid cards", () => { | ||
|
||
let card = "Z♠" | ||
expect(() => getCardValue(card)).toThrow("Invalid card rank"); | ||
}); | ||
|
||
test("should throw Invalid card rank for invalid cards", () => { | ||
|
||
let card = "11♠" | ||
expect(() => getCardValue(card)).toThrow("Invalid card rank"); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
function countChar(str, char) { | ||
return str.split(char).length -1; | ||
} | ||
|
||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
const lastDigit = num % 10; | ||
const lastTwoDigits = num % 100; | ||
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) { | ||
return `${num}th`; | ||
} | ||
|
||
switch(lastDigit) { | ||
case 1: | ||
return `${num}st`; | ||
break; | ||
case 2: | ||
return `${num}nd`; | ||
break; | ||
case 3: | ||
return `${num}rd`; | ||
break; | ||
default: | ||
return `${num}th`; | ||
} | ||
|
||
|
||
} | ||
|
||
module.exports = getOrdinalNumber; |
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. I don't think your implementation can pass some of the tests in this script. Have you tried executing this script to test your function implementation? 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. Yes, some mistakes in the 2 expected values which have now been corrected. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
function repeat(str, count) { | ||
if(count > 0) { | ||
return str.repeat(count); | ||
} else if (count === 0) { | ||
return ""; | ||
} else { | ||
throw new Error("Invalid number. Please enter a positive number or 0 for count"); | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
module.exports = repeat; |
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.
A single comparison is enough if we can ensure the values being compared are positives.
That is, treat -2/3, 2/-3, and -2/-3 the same as 2/3. (They are all proper fractions).
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.
added Math.abs() in the hope it would sort out the issue.