generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Open
aydaeslami
wants to merge
14
commits into
CodeYourFuture:main
Choose a base branch
from
aydaeslami:Sprint3
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2b3cebc
Key-Exercises
aydaeslami b0c4234
Mandatory-errors
aydaeslami 4c52251
Mandatory-interpret
aydaeslami d518c0c
Stretch & Key exercise num 3
aydaeslami 73cd2e5
Sprint2 /Key Error
aydaeslami c7bbe5d
Mandatory-debug
aydaeslami af0409e
Mandatory-implement
aydaeslami d13a01a
Mandatory-Interpret
aydaeslami 54b19d6
Stretch-extend
aydaeslami 3b0e21d
key-implement
aydaeslami 2130155
2-mandatory-rewrite
aydaeslami 82a14a7
mandatory-practice
aydaeslami dae5ae6
Sprint 1 and sprint 2 removed
aydaeslami 4feb4f2
Update Tests
aydaeslami 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
|
||
if (typeof angle === "number" && isFinite(angle)) { | ||
if (angle <= 0 || angle >= 360) return "Invalid angle"; | ||
if (angle < 90) return "Acute angle"; | ||
if (angle === 90) return "Right angle"; | ||
if (angle < 180) return "Obtuse angle"; | ||
if (angle === 180) return "Straight angle"; | ||
if (angle < 360) return "Reflex angle"; | ||
} else return "Invalid input"; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// 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; |
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,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; |
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,5 +1,17 @@ | ||
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; | ||
|
||
throw new Error("Invalid card rank"); | ||
} | ||
module.exports = getCardValue; | ||
module.exports = getCardValue; | ||
|
||
console.log(getCardValue("2XYZ♠")); // ==> 2 | ||
console.log(getCardValue("0x02♠")); // ==> 2 | ||
console.log(getCardValue("2.1♠")); // ==> 2 | ||
// console.log(getCardValue("00_02♠")); //==> Invalid card rank | ||
console.log(getCardValue("2.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,11 +1,46 @@ | ||
const getCardValue = require("./3-get-card-value"); | ||
let cardList = ["♥", "♣", "♠", "♦"]; | ||
let faceCardList = ["J", "Q", "K"]; | ||
let invalidCards = ["B♣", "11♠", "0♣", "5", "♠", "_", ""]; | ||
|
||
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): | ||
|
||
for (let item of cardList) { | ||
for (let i = 2; i <= 10; i++) { | ||
test(`should return ${i} for ${i}${item}`, () => { | ||
const fiveofHearts = getCardValue(`${i}${item}`); | ||
expect(fiveofHearts).toEqual(i); | ||
}); | ||
} | ||
} | ||
|
||
// Case 3: Handle Face Cards (J, Q, K): | ||
for (let face of faceCardList) { | ||
for (let item of cardList) { | ||
test(`should return 10 for ${face}${item}`, () => { | ||
const FaceCard = getCardValue(`${face}${item}`); | ||
expect(FaceCard).toEqual(10); | ||
}); | ||
} | ||
} | ||
|
||
// Case 4: Handle Ace (A): | ||
for (let item of cardList) { | ||
test(`should return 11 for Ace of ${item}`, () => { | ||
const HandleAce = getCardValue(`A${item}`); | ||
expect(HandleAce).toEqual(11); | ||
}); | ||
} | ||
|
||
// Case 5: Handle Invalid Cards: | ||
|
||
for (let invCard of invalidCards) { | ||
test(`should throw error for invalid card ${invCard}`, () => { | ||
expect(() => getCardValue(invCard)).toThrow("Invalid card rank"); | ||
}); | ||
} |
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,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; |
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
21 changes: 19 additions & 2 deletions
21
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,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)); |
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Should any of them of them be treated as valid card rank?