-
-
Notifications
You must be signed in to change notification settings - Fork 196
London | May-2025 | Reza Jahanimir | Sprint-3 #576
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
41faaac
fb392b3
52148a6
4d0497e
13220cd
396094b
ccf0768
686efb6
435f1dd
cb18deb
c13ebd3
37f8608
af01c38
2b3e360
8dd332e
e80b220
d32bc0c
ce330dd
c969da7
95c85ba
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,8 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (denominator === 0) { | ||
throw new Error("Denominator cannot be zero."); | ||
} | ||
return Math.abs(numerator) < Math.abs(denominator); | ||
} | ||
|
||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
const isProperFraction = require("./2-is-proper-fraction"); | ||
|
||
|
||
test("should return true for a proper fraction", () => { | ||
expect(isProperFraction(2, 3)).toEqual(true); | ||
}); | ||
|
||
// Case 2: Identify Improper Fractions: | ||
test("should return false for an Improper fraction", () => { | ||
expect(isProperFraction(6, 3)).toEqual(false); | ||
}); | ||
|
||
test("should return false for a negative improper fraction", () => { | ||
expect(isProperFraction(-7, 4)).toEqual(false); | ||
}); | ||
|
||
// Case 3: Identify Negative Fractions: | ||
test("should return true for a negative proper fraction", () => { | ||
expect(isProperFraction(3, -5)).toEqual(true); | ||
expect(isProperFraction(-3, 5)).toEqual(true); | ||
}); | ||
|
||
// Case 4: Identify Equal Numerator and Denominator: | ||
test("should return false for equal numerator and denominator", () => { | ||
expect(isProperFraction(5, 5)).toEqual(false); | ||
}); | ||
|
||
// Case 6: Identify Zero Denominator: | ||
test("should throw an error for zero denominator", () => { | ||
expect(() => isProperFraction(3, 0)).toThrow("Denominator cannot be zero."); | ||
}); | ||
|
||
// Case 5: Identify Fractions with Absolute Values: | ||
test("should return false for equal numerator and denominator regardless of sign", () => { | ||
expect(isProperFraction(5, 5)).toEqual(false); | ||
expect(isProperFraction(-5, 5)).toEqual(false); | ||
expect(isProperFraction(5, -5)).toEqual(false); | ||
expect(isProperFraction(-5, -5)).toEqual(false); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
if (typeof card !== "string" || card.length < 2) { | ||
throw new Error("Invalid card input"); | ||
} | ||
|
||
const trimmedCard = card.trim(); // handles whitespace at start/end | ||
const rank = trimmedCard.slice(0, -1).trim(); // Remove suit, trim spaces | ||
|
||
// Handle special cases for Ace and face cards | ||
if (rank === "A") return 11; | ||
if (["K", "Q", "J", "10"].includes(rank)) return 10; | ||
|
||
// Digits 2–9 | ||
// return the rank as a number if it's between 2 and 9 | ||
if ("23456789".includes(rank)) return Number(rank); | ||
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. Almost. Any substring of "23456789" can satisfy the condition. 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. return the rank as a number if it's between 2 and 9 "23456789": This is a string made of all the single-digit card ranks from 2 to 9. .includes(rank): Checks if the rank exists inside that string. return Number(rank); 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. "23456789".includes("45") // => true |
||
|
||
throw new Error("Invalid card rank"); | ||
} | ||
|
||
|
||
module.exports = getCardValue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,38 @@ | ||
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): | ||
// Case 3: Handle Face Cards (J, Q, K): | ||
// Case 4: Handle Ace (A): | ||
// Case 5: Handle Invalid Cards: | ||
// Number cards | ||
test("should return the correct value for number cards (2-10)", () => { | ||
expect(getCardValue("2♦")).toEqual(2); | ||
expect(getCardValue("5♣")).toEqual(5); | ||
expect(getCardValue("10♥")).toEqual(10); | ||
}); | ||
|
||
// Face cards | ||
test("should return 10 for face cards (J, Q, K)", () => { | ||
expect(getCardValue("J♠")).toEqual(10); | ||
expect(getCardValue("Q♦")).toEqual(10); | ||
expect(getCardValue("K♣")).toEqual(10); | ||
}); | ||
|
||
// Ace | ||
test("should return 11 for Ace", () => { | ||
expect(getCardValue("A♠")).toEqual(11); | ||
expect(getCardValue("A♣")).toEqual(11); | ||
expect(getCardValue("A♦")).toEqual(11); | ||
}); | ||
|
||
// Invalid cards | ||
test("should throw an error for invalid cards", () => { | ||
expect(() => getCardValue("1♠")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("Z♦")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("15♥")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("X♣")).toThrow("Invalid card rank"); | ||
}); | ||
|
||
// edge/weird cases | ||
test("should throw for strange or malformed input", () => { | ||
expect(() => getCardValue("3.1416♠")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("09♠")).toThrow("Invalid card rank"); | ||
expect(() => getCardValue("0x02♠")).toThrow("Invalid card rank"); | ||
expect(getCardValue(" 5 ♠")).toEqual(5); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
function countChar(stringOfCharacters, findCharacter) { | ||
return 5 | ||
if (typeof stringOfCharacters !== "string" || typeof findCharacter !== "string" || findCharacter.length !== 1) { | ||
throw new Error("Invalid input: must pass a string and a single character."); | ||
} | ||
// Convert the string to an array of characters and filter for the target character | ||
return [...stringOfCharacters].filter(c => c === findCharacter).length; | ||
} | ||
|
||
module.exports = countChar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
} | ||
if (num < 1 || !Number.isInteger(num)) throw new Error("Input must be a positive integer"); | ||
|
||
const specialCases = [11, 12, 13]; | ||
const suffixes = ["th", "st", "nd", "rd"]; | ||
const lastDigit = num % 10; | ||
const lastTwoDigits = num % 100; | ||
|
||
return num + (specialCases.includes(lastTwoDigits) ? "th" : suffixes[lastDigit] || "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.
Can your function pass the tests you specified in this script?