generated from CodeYourFuture/Module-Template
-
-
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
Open
Reza-Jahanimir
wants to merge
20
commits into
CodeYourFuture:main
Choose a base branch
from
Reza-Jahanimir:coursework/sprint-3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
41faaac
have done my key-implement exercise
Millena28 fb392b3
done the mandatory-rewrite
Millena28 52148a6
Done the mandatory-practice
Millena28 4d0497e
Done stretch investigate and implemented new card-validator file
Millena28 13220cd
done ALL
Millena28 396094b
made some corrections from review
Millena28 ccf0768
fixed the angle if statement, added validation steps
Reza-Jahanimir 686efb6
solve the error in testing
Reza-Jahanimir 435f1dd
solve function handling characters and validation.
Reza-Jahanimir cb18deb
now function differs between upper and lower characters. and instead …
Reza-Jahanimir c13ebd3
change the layout of my testing so that same test are grouped
Reza-Jahanimir 37f8608
corrected the function
Reza-Jahanimir af01c38
omitted one the repeated statement , add validations
Reza-Jahanimir 2b3e360
redesigning the function, specify the test
Reza-Jahanimir 8dd332e
made the function look simpler and cleaner
Reza-Jahanimir e80b220
Numbers ending in 11, 12, 13 now are together in a test.
Reza-Jahanimir d32bc0c
i tried my best
Reza-Jahanimir ce330dd
function can return false when a password is one of the previous pass…
Reza-Jahanimir c969da7
add a line of explanation
Reza-Jahanimir 95c85ba
change the function the its original, cleaned the test syntax
Reza-Jahanimir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
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; | ||
|
||
// It should be a string of digits, not starting with zero, and between 2-10 | ||
if (!/^[1-9][0-9]*$/.test(rank)) { | ||
throw new Error("Invalid card rank"); | ||
} | ||
// Convert rank to a number and check if it's between 2 and 10 | ||
const numericRank = Number(rank); | ||
if ( | ||
!isNaN(numericRank) && | ||
Number.isInteger(numericRank) && | ||
numericRank >= 2 && | ||
numericRank <= 10 | ||
) { | ||
return numericRank; | ||
} | ||
|
||
throw new Error("Invalid card rank"); | ||
} | ||
|
||
|
||
module.exports = getCardValue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 11 additions & 2 deletions
13
Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?