-
-
Notifications
You must be signed in to change notification settings - Fork 195
LONDON | MAY2025 | JESUS DEL MORAL | STRUCTURING AND TESTING DATA SPRINT 3 #581
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 4 commits
4575e7b
91085e5
5797ab8
bf2b29f
a89ab50
aaca635
f9880b0
f0cf03d
bf0809a
7a5d476
c033ab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
illicitonion marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,22 @@ | |
// write one test at a time, and make it pass, build your solution up methodically | ||
// just make one change at a time -- don't rush -- programmers are deep and careful thinkers | ||
function getCardValue(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. Your function is written quite well. There are a few tests I ran that didn't return the result I would expect. Can you figure out what is missing in your 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. Can you review the above☝️failing tests and implement something within your function to ensure that they don't fail! 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. @delmorallopez I don't see all of the suggested tests here in your PR. How are you tracking whether you're completed comments? I recommend clicking "Resolve conversation" when you've completed something, so that any unresolved conversations still show up and you know you need to complete them. |
||
if (rank === "A") return 11; | ||
let rank = card.charAt(0); | ||
console.log(rank); | ||
illicitonion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (rank === "A") { | ||
return 11; | ||
} else if (!isNaN(rank)) { | ||
// Convert rank to number | ||
let numericRank = Number(rank); | ||
if (numericRank >= 2 && numericRank <= 10) { | ||
return numericRank; | ||
} | ||
} else if (rank === 'J' || rank === 'Q' || rank === 'K') { | ||
return 10; | ||
} | ||
|
||
return 'Invalid card rank.'; | ||
} | ||
|
||
// You need to write assertions for your function to check it works in different cases | ||
|
@@ -33,19 +48,30 @@ assertEquals(aceofSpades, 11); | |
// When the function is called with such a card, | ||
// Then it should return the numeric value corresponding to the rank (e.g., "5" should return 5). | ||
const fiveofHearts = getCardValue("5♥"); | ||
// ====> write your test here, and then add a line to pass the test in the function above | ||
assertEquals(fiveofHearts, 5); | ||
|
||
|
||
const sevenofHearts = getCardValue("7♥"); | ||
assertEquals(sevenofHearts, 7); | ||
// Handle Face Cards (J, Q, K): | ||
// Given a card with a rank of "10," "J," "Q," or "K", | ||
// When the function is called with such a card, | ||
// Then it should return the value 10, as these cards are worth 10 points each in blackjack. | ||
const qofHearts = getCardValue("Q♥"); | ||
assertEquals(qofHearts, 10); | ||
|
||
// Handle Ace (A): | ||
// Given a card with a rank of "A", | ||
// When the function is called with an Ace, | ||
// Then it should, by default, assume the Ace is worth 11 points, which is a common rule in blackjack. | ||
const aceofHeart = getCardValue("A♥"); | ||
assertEquals(aceofHeart, 11); | ||
|
||
|
||
|
||
// Handle Invalid Cards: | ||
// Given a card with an invalid rank (neither a number nor a recognized face card), | ||
// When the function is called with such a card, | ||
// Then it should throw an error indicating "Invalid card rank." | ||
const invalid = getCardValue("-1"); | ||
assertEquals(invalid, 'Invalid card rank.'); |
illicitonion marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
function isProperFraction(numerator, denominator) { | ||
illicitonion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
} | ||
if (denominator == 0){ | ||
return false | ||
} | ||
return numerator < denominator; | ||
} | ||
|
||
module.exports = isProperFraction; | ||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
if (typeof card !== 'string' || card.length < 2) { | ||
return 'Invalid card rank.'; | ||
} | ||
|
||
const validSuits = ['♠', '♥', '♦', '♣']; | ||
const suit = card.slice(-1); // Last character | ||
const rank = card.slice(0, -1); // Everything before last character | ||
|
||
if (!validSuits.includes(suit)) { | ||
return 'Invalid card rank.'; | ||
} | ||
|
||
if (rank === 'A') { | ||
return 11; | ||
} else if (['J', 'Q', 'K'].includes(rank)) { | ||
return 10; | ||
} else if (!isNaN(rank)) { | ||
const numericRank = Number(rank); | ||
if (numericRank >= 2 && numericRank <= 10) { | ||
return numericRank; | ||
} | ||
} | ||
|
||
return 'Invalid card rank.'; | ||
} | ||
module.exports = getCardValue; | ||
|
||
module.exports = getCardValue; |
Uh oh!
There was an error while loading. Please reload this page.