-
-
Notifications
You must be signed in to change notification settings - Fork 195
Glasgow | ITP May -25 | Mirabelle Morah | Module-Structuring-and-Testing-Data | Coursework/sprint-3 #628
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?
Glasgow | ITP May -25 | Mirabelle Morah | Module-Structuring-and-Testing-Data | Coursework/sprint-3 #628
Changes from 3 commits
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,15 @@ | ||
function getAngleType(angle) { | ||
if (angle === 90) return "Right angle"; | ||
// replace with your completed function from key-implement | ||
|
||
// read to the end, complete line 36, then pass your test here | ||
else if (angle < 90) return "Acute angle"; | ||
else if (angle > 90 && angle < 180) return "Obtuse angle"; | ||
else if (angle === 180) return "Straight angle"; | ||
else if (angle > 180 && angle < 360) return "Reflex angle"; | ||
else return "Invalid 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,6 @@ | ||
function isProperFraction(numerator, denominator) { | ||
if (numerator < denominator) return true; | ||
// add your completed function from key-implement here | ||
if (denominator === 0) return false; | ||
if (numerator < denominator) return true; | ||
if (numerator >= denominator) return false; | ||
} | ||
|
||
module.exports = isProperFraction; | ||
module.exports = isProperFraction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
function getCardValue(card) { | ||
// replace with your code from key-implement | ||
return 11; | ||
const rank = card.slice(0, -1); | ||
if (rank === "A") return 11; | ||
|
||
if (["K", "Q", "J", "10"].includes(rank)) return 10; | ||
const num = Number(rank); | ||
if (num >= 2 && num <= 9) return num; | ||
|
||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new Error("Invalid card rank"); | ||
} | ||
module.exports = getCardValue; | ||
|
||
module.exports = getCardValue; |
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,15 @@ | ||
function getOrdinalNumber(num) { | ||
return "1st"; | ||
if (typeof num !== "number" || !Number.isInteger(num)) { | ||
throw new Error("Input must be an integer."); | ||
} | ||
|
||
const suffixes = ["th", "st", "nd", "rd"]; | ||
const remainder = num % 100; | ||
|
||
return ( | ||
num + | ||
(suffixes[(remainder - 20) % 10] || suffixes[remainder] || suffixes[0]) | ||
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. Can you explain how this expression work? 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. Lines 1-3 checks the kind of input passed in the parameter. If input type is not a number or integer (eg if it's a string) then it gives the error message that the input must be an integer. Line 6: 'Const suffixes' is an array or ordinal suffixes Lines 9-11: performs multiple things: suffixes[(remainder - 20) % 10] Remainder = 23: (23-20) % 10 = [0.3] 3, so const suffix [3] = rd. There it will assign 23 as '23rd' Then for '|| suffixes[remainder]' if an answer is undefined it simple uses the remainder with the direct array number: like if remainder = 1: suffixes[1] = "st" etc. The final fallback if both previous parts are undefined it goes back to || suffixes[0] which adds 'th' to numbers like 11th etc. 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. Would the code still work if we changed If not, can you find a number in the range [0, 100) which the latter would fail?
This unusual notation makes it looks like you are treating You could just write 123 % 100 = 23 (all programmers should recognise what |
||
); | ||
} | ||
|
||
module.exports = getOrdinalNumber; | ||
module.exports = getOrdinalNumber; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
function repeat() { | ||
return "hellohellohello"; | ||
function repeat(str, count) { | ||
if (typeof str !== "string") { | ||
throw new Error("Input must be a string."); | ||
} | ||
|
||
if (!Number.isInteger(count) || count < 0) { | ||
throw new Error("Count must be a non-negative integer"); | ||
} | ||
|
||
return str.repeat(count); | ||
} | ||
|
||
module.exports = repeat; | ||
module.exports = repeat; |
Uh oh!
There was an error while loading. Please reload this page.