-
-
Notifications
You must be signed in to change notification settings - Fork 197
LONDON | May-2025 | Aida Eslamimoghadam| Module-Structuring-and-Testing-Data | Sprint-3 #578
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
2b3cebc
b0c4234
4c52251
d518c0c
73cd2e5
c7bbe5d
af0409e
d13a01a
54b19d6
3b0e21d
2130155
82a14a7
dae5ae6
4feb4f2
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,18 +1,13 @@ | ||
function getAngleType(angle) { | ||
if (angle < 90) return "Acute angle"; | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
|
||
if (angle < 180) return "Obtuse angle"; | ||
if (angle === 180) return "Straight angle"; | ||
if (angle < 360) return "Reflex 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 | ||
// We will upgrade our approach to ES6 modules in the next course module, so for now | ||
// we have just written the CommonJS module.exports syntax for you | ||
module.exports = getAngleType; | ||
module.exports = getAngleType; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
return Math.abs(numerator) < Math.abs(denominator); // false or true | ||
} | ||
|
||
module.exports = isProperFraction; | ||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const rank = card.slice(0, -1); // Get everything before the suit emoji | ||
|
||
if (rank === "A") return 11; | ||
if (["K", "Q", "J", "10"].includes(rank)) return 10; | ||
const number = parseInt(rank); | ||
if (number >= 2 && number <= 9) return number; | ||
Comment on lines
+6
to
+7
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. In JavaScript, strings that represent valid numeric literals in the language can be safely converted to equivalent numbers or parsed into integers. For examples, "0x02", "2.1", or "00_02". Does your function return the value you expected from each of the following function calls?
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. This code returns 2 for ‘0x02♠’, ‘2.1♠’, and ‘2XYZ♠’, but it throws an error for ‘00_02 because it can’t read underscores (00_02) ==> becomes NaN, so it gives an error. 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. Should any of them of them be treated as valid card rank? |
||
|
||
throw new Error("Invalid card rank"); | ||
} | ||
module.exports = getCardValue; | ||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
const aceofSpades = getCardValue("A♠"); | ||
expect(aceofSpades).toEqual(11); | ||
}); | ||
|
||
// Case 2: Handle Number Cards (2-10): | ||
test("should return 5 for 5♥ of Spades", () => { | ||
const fiveofHearts = getCardValue("5♥"); | ||
expect(fiveofHearts).toEqual(5); | ||
}); | ||
|
||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Case 3: Handle Face Cards (J, Q, K): | ||
|
||
test("should return 10 Face Cards", () => { | ||
const FaceCard = getCardValue("J♥"); | ||
expect(FaceCard).toEqual(10); | ||
}); | ||
|
||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Case 4: Handle Ace (A): | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const HandleAce = getCardValue("A♥"); | ||
expect(HandleAce).toEqual(11); | ||
}); | ||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Case 5: Handle Invalid Cards: | ||
|
||
test("should return 11 for Ace of Spades", () => { | ||
const InvalidCard = getCardValue("B♣"); | ||
expect(InvalidCard).toEqual(32); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
let count = 0; | ||
for (let i = 0; i < stringOfCharacters.length; i++) { | ||
if (stringOfCharacters[i] === findCharacter) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
module.exports = countChar; | ||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
const lastTwo = num % 100; | ||
const lastDigit = num % 10; | ||
if (lastTwo >= 11 && lastTwo <= 13) { | ||
// for 11 , 12, 13 | ||
return num + "th"; | ||
} | ||
|
||
switch (lastDigit) { | ||
case 1: | ||
return num + "st"; | ||
case 2: | ||
return num + "nd"; | ||
case 3: | ||
return num + "rd"; | ||
default: | ||
return num + "th"; | ||
} | ||
} | ||
|
||
module.exports = getOrdinalNumber; | ||
module.exports = getOrdinalNumber; | ||
console.log(getOrdinalNumber(2)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
function repeat(str, count) { | ||
if (count < 0) { | ||
throw new Error("Count cannot be negative"); | ||
} else { | ||
let result = ""; | ||
for (let i = 0; i < count; i++) { | ||
result += str; | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
module.exports = repeat; | ||
// console.log(repeat("Aida", -5)); | ||
module.exports = repeat; |
Uh oh!
There was an error while loading. Please reload this page.