Skip to content

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
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
41faaac
have done my key-implement exercise
Millena28 Feb 21, 2025
fb392b3
done the mandatory-rewrite
Millena28 Feb 21, 2025
52148a6
Done the mandatory-practice
Millena28 Feb 27, 2025
4d0497e
Done stretch investigate and implemented new card-validator file
Millena28 Feb 28, 2025
13220cd
done ALL
Millena28 Feb 28, 2025
396094b
made some corrections from review
Millena28 Mar 18, 2025
ccf0768
fixed the angle if statement, added validation steps
Reza-Jahanimir Jul 4, 2025
686efb6
solve the error in testing
Reza-Jahanimir Jul 4, 2025
435f1dd
solve function handling characters and validation.
Reza-Jahanimir Jul 4, 2025
cb18deb
now function differs between upper and lower characters. and instead …
Reza-Jahanimir Jul 4, 2025
c13ebd3
change the layout of my testing so that same test are grouped
Reza-Jahanimir Jul 4, 2025
37f8608
corrected the function
Reza-Jahanimir Jul 4, 2025
af01c38
omitted one the repeated statement , add validations
Reza-Jahanimir Jul 4, 2025
2b3e360
redesigning the function, specify the test
Reza-Jahanimir Jul 4, 2025
8dd332e
made the function look simpler and cleaner
Reza-Jahanimir Jul 4, 2025
e80b220
Numbers ending in 11, 12, 13 now are together in a test.
Reza-Jahanimir Jul 4, 2025
d32bc0c
i tried my best
Reza-Jahanimir Jul 4, 2025
ce330dd
function can return false when a password is one of the previous pass…
Reza-Jahanimir Jul 4, 2025
c969da7
add a line of explanation
Reza-Jahanimir Jul 5, 2025
95c85ba
change the function the its original, cleaned the test syntax
Reza-Jahanimir Jul 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Sprint-3/1-key-implement/1-get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
// Build up your function case by case, writing tests as you go
// The first test and case is written for you. The next case has a test, but no code.
// Execute this script in your terminal
// node 1-get-angle-type.js
//node 1-get-angle-type.js
// The assertion error will tell you what the expected output is
// Write the code to pass the test
// Then, write the next test! :) Go through this process until all the cases are implemented

function getAngleType(angle) {
if (angle === 90) return "Right angle";
if (angle > 0 && angle < 90) return "Acute angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
if (angle > 180 && angle < 360) return "Reflex angle";
// read to the end, complete line 36, then pass your test here
}

Expand Down Expand Up @@ -43,14 +47,19 @@ assertEquals(acute, "Acute angle");
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
assertEquals(obtuse,"Obtuse angle");
// ====> write your test here, and then add a line to pass the test in the function above

// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
const Straight = getAngleType(180);
assertEquals(Straight,"Straight angle");
// ====> write your test here, and then add a line to pass the test in the function above

// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
const Reflex = getAngleType(200);
assertEquals(Reflex,"Reflex angle");
// ====> write your test here, and then add a line to pass the test in the function above
4 changes: 4 additions & 0 deletions Sprint-3/1-key-implement/2-is-proper-fraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator >= denominator)return false;

}

// here's our helper again
Expand Down Expand Up @@ -40,13 +42,15 @@ assertEquals(improperFraction, false);
// target output: true
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
const negativeFraction = isProperFraction(-4, 7);
assertEquals(negativeFraction,true);
// ====> complete with your assertion

// Equal Numerator and Denominator check:
// Input: numerator = 3, denominator = 3
// target output: false
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
const equalFraction = isProperFraction(3, 3);
assertEquals(improperFraction,false);
// ====> complete with your assertion

// Stretch:
Expand Down
24 changes: 22 additions & 2 deletions Sprint-3/1-key-implement/3-get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +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) {
if (rank === "A") return 11;
if (!card || typeof card !== "string") return "Invalid card format";
//extracting the rank of the card
const rank = card.slice(0, -1).trim();
}
//parseInt(rank) and Number(rank) are the same thing. parseInt() is a function that parses a string and returns an integer. If the first character in the string can't be converted into a number, then it returns NaN. Number() is a function that converts a string to a number. If the string can't be converted into a number, then it returns NaN.
if (rank === "A") return 11;
//For numerical cards, we return the number
else if (!isNaN(rank) >= 2 && Number(rank) <= 10) return Number(rank);
//For face cards, we return 10
else if ( rank === "J" || rank=== "Q" || rank ==="K" ) return 10;
//If the card is invalid, we throw an error
else return("Invalid card rank.");





// You need to write assertions for your function to check it works in different cases
// we're going to use this helper function to make our assertions easier to read
Expand All @@ -33,19 +47,25 @@ 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♥");
assertEquals(fiveofHearts,5);
// ====> write your test here, and then add a line to pass the test in the function above

// 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 kingofhearts = getCardValue("J","K","Q");
assertEquals(kingofhearts,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 aceofDiamonds = getCardValue("A:diamonds:");
assertEquals(aceofDiamonds, 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 Invalidcardrank = getCardValue("1:diamonds:");
assert.strictEqual(Invalidcardrank,"Invalid card rank");
11 changes: 10 additions & 1 deletion Sprint-3/2-mandatory-rewrite/1-get-angle-type.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
function getAngleType(angle) {
// handle undefined or out-of-range input
if (typeof angle !== "number" || angle <= 0 || angle >= 360) {
return "Invalid angle";
}
if (angle === 90) return "Right angle";
if (angle < 90) return "Acute angle";
if (angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";

// replace with your completed function from key-implement

return "Reflex angle"; // angle > 180 and < 360
}
module.exports = getAngleType;



Expand Down
42 changes: 38 additions & 4 deletions Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,52 @@ test("should identify right angle (90°)", () => {
// REPLACE the comments with the tests
// make your test descriptions as clear and readable as possible

// Case 2: Identify Acute Angles:
// When the angle is less than 90 degrees,
// Then the function should return "Acute angle"
// Case 2: Identify Acute Angles:
test("should identify acute angles (less than 90°)", () => {
expect(getAngleType(45)).toEqual("Acute angle");
expect(getAngleType(1)).toEqual("Acute angle");
expect(getAngleType(89)).toEqual("Acute angle");
});


// Case 3: Identify Obtuse Angles:
// When the angle is greater than 90 degrees and less than 180 degrees,
// Then the function should return "Obtuse angle"
// Case 3: Identify Obtuse Angles:
test("should identify obtuse angles (between 90° and 180°)", () => {
expect(getAngleType(120)).toEqual("Obtuse angle");
expect(getAngleType(91)).toEqual("Obtuse angle");
expect(getAngleType(179)).toEqual("Obtuse angle");
});


// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
// Case 4: Identify Straight Angles:
test("should identify straight angle (180°)", () => {
expect(getAngleType(180)).toEqual("Straight angle");
});


// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
// Case 5: Identify Reflex Angles:
test("should identify reflex angles (between 180° and 360°)", () => {
expect(getAngleType(270)).toEqual("Reflex angle");
expect(getAngleType(181)).toEqual("Reflex angle");
expect(getAngleType(359)).toEqual("Reflex angle");
});




// Case 6:Invalid inputs
test("should return 'Invalid angle' for out-of-range or bad input", () => {
expect(getAngleType(0)).toEqual("Invalid angle");
expect(getAngleType(-10)).toEqual("Invalid angle");
expect(getAngleType(360)).toEqual("Invalid angle");
expect(getAngleType(1000)).toEqual("Invalid angle");
expect(getAngleType("90")).toEqual("Invalid angle");
expect(getAngleType(null)).toEqual("Invalid angle");
});
6 changes: 4 additions & 2 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.js
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;
28 changes: 28 additions & 0 deletions Sprint-3/2-mandatory-rewrite/2-is-proper-fraction.test.js
Copy link
Contributor

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?

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);
});
20 changes: 18 additions & 2 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.js
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost. Any substring of "23456789" can satisfy the condition.

Copy link
Author

@Reza-Jahanimir Reza-Jahanimir Jul 5, 2025

Choose a reason for hiding this comment

The 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
return Number(rank);

"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.
For example:
"23456789".includes("5") // → true
"23456789".includes("10") // → false

return Number(rank);
This converts the string "5" into the number 5.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"23456789".includes("45") // => true
"23456789".includes("12345") // => true


throw new Error("Invalid card rank");
}


module.exports = getCardValue;
45 changes: 36 additions & 9 deletions Sprint-3/2-mandatory-rewrite/3-get-card-value.test.js
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);
});
6 changes: 5 additions & 1 deletion Sprint-3/3-mandatory-practice/implement/count.js
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;
33 changes: 33 additions & 0 deletions Sprint-3/3-mandatory-practice/implement/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,36 @@ test("should count multiple occurrences of a character", () => {
// And a character char that does not exist within the case-sensitive str,
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.

// Scenario 1: Multiple occurrences
test("should count multiple occurrences of a character", () => {
expect(countChar("aaaaa", "a")).toEqual(5);
});

// Scenario 2: No occurrences
test("should return 0 when the character is not found", () => {
expect(countChar("hello", "z")).toEqual(0);
});

// Scenario 3: Case sensitivity
test("should be case-sensitive", () => {
expect(countChar("Millena", "m")).toEqual(0); // lowercase 'm' not present
expect(countChar("Millena", "M")).toEqual(1); // uppercase 'M' present
});

// Scenario 4: Count spaces
test("should count spaces as characters", () => {
expect(countChar("Millena Mesfin", " ")).toEqual(1);
});

// Scenario 5: Empty string
test("should return 0 for an empty string", () => {
expect(countChar("", "m")).toEqual(0);
});

// Scenario 6: Show it counts 'm' but ignores 'M'
test("should count only lowercase 'm'", () => {
const str = "mMmmMmmM";
expect(countChar(str, "m")).toEqual(5); // 4 lowercase
expect(countChar(str, "M")).toEqual(3); // 4 uppercase
});
13 changes: 11 additions & 2 deletions Sprint-3/3-mandatory-practice/implement/get-ordinal-number.js
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;
Loading