Skip to content

Commit d436034

Browse files
coursework-3
1 parent 5845874 commit d436034

File tree

12 files changed

+7428
-1978
lines changed

12 files changed

+7428
-1978
lines changed

Sprint-3/1-key-implement/2-is-proper-fraction.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
function isProperFraction(numerator, denominator) {
1111
// A proper fraction has a non-zero denominator,
1212
// and the absolute value of the numerator is less than the denominator.
13-
if (denominator === 0) return false;
14-
return Math.abs(numerator) < Math.abs(denominator);
13+
if (denominator === 0) return false;
14+
if (numerator < 0) numerator = -numerator;
15+
if (denominator < 0) denominator = -denominator;
16+
return numerator < denominator;
1517

1618
}
1719

Sprint-3/1-key-implement/3-get-card-value.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function getCardValue(card) {
1515

1616
// If the rank is a number between "2" and "10", return its numeric value
1717
if (["2", "3", "4", "5", "6", "7", "8", "9", "10"].includes(rank)) {
18-
return parseInt(rank, 10); // Convert string to number
18+
return Number(rank); // Convert string to number
1919
}
2020

2121
// If the rank is "J", "Q", or "K", return 10

Sprint-3/2-mandatory-rewrite/1-get-angle-type.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
function getAngleType(angle) {
2-
if (angle === 90) return "Right angle";
2+
if (angle === 90) { return "Right angle";
33
// replace with your completed function from key-implement
4-
4+
} else if (angle > 0 && angle < 90) {
5+
return "Acute angle";
6+
} else if (angle > 90 && angle < 180) {
7+
return "Obtuse angle";
8+
} else if (angle === 180) {
9+
return "Straight angle";
10+
} else if (angle > 180 && angle < 360) {
11+
return "Reflex angle";
12+
} else {
13+
return undefined; // For invalid angles like negative or >= 360
14+
}
515
}
616

717

@@ -10,7 +20,6 @@ function getAngleType(angle) {
1020

1121

1222

13-
1423
// Don't get bogged down in this detail
1524
// Jest uses CommonJS module syntax by default as it's quite old
1625
// We will upgrade our approach to ES6 modules in the next course module, so for now

Sprint-3/2-mandatory-rewrite/1-get-angle-type.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test("should identify right angle (90°)", () => {
66

77
// REPLACE the comments with the tests
88
// make your test descriptions as clear and readable as possible
9-
9+
1010
test("should identify acute angles (less than 90°)", () => {
1111
expect(getAngleType(45)).toEqual("Acute angle");
1212
expect(getAngleType(89)).toEqual("Acute angle");
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
function isProperFraction(numerator, denominator) {
2-
if (numerator < denominator) return true;
3-
// add your completed function from key-implement here
2+
// Check for positive values and that numerator is less than denominator
3+
if (numerator > 0 && denominator > 0 && numerator < denominator) {
4+
return true;
5+
} else {
6+
return false;
7+
}
48
}
59

610
module.exports = isProperFraction;
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
function getCardValue(card) {
2-
// replace with your code from key-implement
3-
return 11;
2+
if (!card || typeof card !== "string") return null;
3+
4+
const value = card.slice(0, -1); // Remove suit (last character)
5+
6+
if (value === "A") return 11;
7+
if (["J", "Q", "K"].includes(value)) return 10;
8+
9+
const number = Number(value);
10+
if (number >= 2 && number <= 10) return number;
11+
12+
return null; // Invalid card
413
}
5-
module.exports = getCardValue;
14+
15+
module.exports = getCardValue;
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
if (!stringOfCharacters || !findCharacter) return 0;
3+
4+
let count = 0;
5+
for (let char of stringOfCharacters) {
6+
if (char === findCharacter) {
7+
count++;
8+
}
9+
}
10+
return count;
311
}
412

5-
module.exports = countChar;
13+
module.exports = countChar;
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
if (typeof num !== "number") return null;
3+
4+
const lastDigit = num % 10;
5+
const lastTwoDigits = num % 100;
6+
7+
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
8+
return `${num}th`;
9+
}
10+
11+
switch (lastDigit) {
12+
case 1:
13+
return `${num}st`;
14+
case 2:
15+
return `${num}nd`;
16+
case 3:
17+
return `${num}rd`;
18+
default:
19+
return `${num}th`;
20+
}
321
}
422

5-
module.exports = getOrdinalNumber;
23+
module.exports = getOrdinalNumber;
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
function repeat() {
2-
return "hellohellohello";
1+
function repeat(str, count) {
2+
if (typeof count !== "number" || count < 0) {
3+
throw new Error("Count must be a non-negative integer");
4+
}
5+
6+
return str.repeat(count);
37
}
48

5-
module.exports = repeat;
9+
module.exports = repeat;

Sprint-3/readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ Recommended order:
6262

6363
## 🔍 4 Investigate Stretch
6464

65-
These stretch activities are not mandatory, but we hope you will explore them after you have completed the key and mandatory work.
65+
These stretch activities are not mandatory, but we hope you will explore them after you have completed the key '/
66+
and mandatory work.
6667

6768
In this exercise, you'll need to **play computer** with the function `find`. This function makes use of while loop statement. Your task will be to step through the code to figure out what is happening when the computer executes the code.
6869

0 commit comments

Comments
 (0)