Skip to content
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

CYF-ITP-South Africa | Rashaad Ebrahim | Module-Structuring-and-Testing-Data | Week 3 #225

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
0655e6d
implement section complete
Rashaad-Ebrahim Dec 11, 2024
35a010c
Installed Jest, package.json and package-lock.json added.
Rashaad-Ebrahim Dec 12, 2024
45701b5
Jest test implemented for get-angle-type.js, with get-angle-type.test.js
Rashaad-Ebrahim Dec 12, 2024
a9860cf
getCardValue function updated to chheck if input is valid string.
Rashaad-Ebrahim Dec 12, 2024
f227570
isProperFraction function updated and isProperFraction jest tests cre…
Rashaad-Ebrahim Dec 12, 2024
548c85e
isValidTriangle function updated and tests created.
Rashaad-Ebrahim Dec 12, 2024
4775eb1
rotateCharacter function updated and tests created.
Rashaad-Ebrahim Dec 12, 2024
3557a56
cardValidator function implemented and tests created.
Rashaad-Ebrahim Dec 12, 2024
7c8723e
countChar function implemented and tests created.
Rashaad-Ebrahim Dec 12, 2024
f7407c9
getOrdinalNumber function implemented and tests created.
Rashaad-Ebrahim Dec 13, 2024
0fb1ed7
isPrime function implemented and tests created.
Rashaad-Ebrahim Dec 13, 2024
c0c428c
validatePassword function created and tests created.
Rashaad-Ebrahim Dec 13, 2024
d4ba005
repeat function implemeted and tests created.
Rashaad-Ebrahim Dec 13, 2024
d3efba7
investigate>find exercise complete.
Rashaad-Ebrahim Dec 14, 2024
ad65cb9
console.logs removed from files after running tests.
Rashaad-Ebrahim Dec 14, 2024
bc8f1b9
Code updated a suggested on PR
Rashaad-Ebrahim Dec 16, 2024
fb6492b
minor changes from feedback from PR
Rashaad-Ebrahim Dec 16, 2024
698e98c
refactored code.
Rashaad-Ebrahim Dec 16, 2024
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
2 changes: 1 addition & 1 deletion Sprint-3/implement/get-angle-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// Then the function should return "Reflex angle"

module.exports = function getAngleType(angle) {
if (angle < 90) return "Acute angle";
if (angle > 0 && angle < 90) return "Acute angle";
if (angle === 90) return "Right angle";
if (angle > 90 && angle < 180) return "Obtuse angle";
if (angle === 180) return "Straight angle";
Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/implement/get-angle-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ test('When the angle is exactly 180 degrees, the function should return "Straigh
expect(getAngleType(180)).toBe("Straight angle");
});

test('When the angle is greater than 180 degrees and less than 360 degrees, the function should return "Reflex angle"', () => {
test("Return Reflex angle for angles between 180 and 360 degrees", () => {
expect(getAngleType(246)).toBe("Reflex angle");
});
40 changes: 9 additions & 31 deletions Sprint-3/implement/get-card-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,19 @@
// Then it should throw an error indicating "Invalid card rank."

function getCardValue(card) {
if (typeof card !== "string") return "Input should be a sting.";
const cardValue = card
.toUpperCase()
.substring(0, card.indexOf(card.slice(-1)));
if (typeof card !== "string") return "Input should be a string.";
const cardValue = card.slice(0, -1).toUpperCase();
const allCards = ["A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2", "1"];
Rashaad-Ebrahim marked this conversation as resolved.
Show resolved Hide resolved
const faceCards = ["K", "Q", "J"];

/* If we wanted to exlude cards for not being a suite
const suites = ["♣", "♠", "♦", "♥"];
if (!suites.includes(card.slice(-1))) return "Invalid card rank.";
*/
if (Number(cardValue) && Number(cardValue) >= 2 && Number(cardValue) <= 10)
return Number(cardValue);
if (faceCards.includes(cardValue)) return 10;
if (cardValue === "A") return 11;
if (allCards.includes(cardValue)) {
if (Number(cardValue) && Number(cardValue) >= 2 && Number(cardValue) <= 10)
return Number(cardValue);
if (faceCards.includes(cardValue)) return 10;
if (cardValue === "A") return 11;
Rashaad-Ebrahim marked this conversation as resolved.
Show resolved Hide resolved
}

return "Invalid card rank.";

/* ### I'm not a fan of if/if else statements so I would have either used ternary operators or short circuiting.
return Number(cardValue)
? Number(cardValue)
: faceCards.includes(cardValue)
? 10
: cardValue === "A"
? 11
: "Invalid card rank.";

OR

return (
(Number(cardValue) && Number(cardValue)) ||
(faceCards.includes(cardValue) && 10) ||
(cardValue === "A" && 11) ||
"Invalid card rank."
);
*/
}

module.exports = getCardValue;
6 changes: 4 additions & 2 deletions Sprint-3/implement/rotate-char.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function rotateCharacter(char, shift) {
}
if (lettersLowerCase.indexOf(char) + shift > 25) {
return lettersLowerCase.charAt(
lettersLowerCase.indexOf(char) - 26 + shift
lettersLowerCase.indexOf(char) - 26 + (shift % 26)
);
}
}
Expand All @@ -62,11 +62,13 @@ function rotateCharacter(char, shift) {
}
if (lettersUpperCase.indexOf(char) + shift > 25) {
return lettersUpperCase.charAt(
lettersUpperCase.indexOf(char) - 26 + shift
lettersUpperCase.indexOf(char) - 26 + (shift % 26)
);
}
}
return char;
}

module.exports = rotateCharacter;

console.log(rotateCharacter("t", 300));
1 change: 1 addition & 0 deletions Sprint-3/implement/rotate-char.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ describe("rotateCharacter Tests", () => {
expect(rotateCharacter("Y", 2)).toBe("A");
});
});

4 changes: 2 additions & 2 deletions Sprint-3/revise/implement/card-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function cardValidator(ccNumber) {

// Validation checks
const isCorrectLength = ccString.length === 16; // Number must be 16 digits
const hasMultipleDigits = [...new Set(ccNumberArray)].length > 1; // At least two different digits
const hasMultipleDigits = new Set(ccNumberArray).size > 1; // At least two different digits
const hasValidChars = digitsRegex.test(ccString); // All characters are numeric
const endsWithEvenDigit = ccNumberArray[ccNumberArray.length - 1] % 2 === 0; // Last digit is even
const isSumGreaterThan16 = ccNumberArray.reduce((a, c) => a + c, 0) > 16; // Sum of digits greater than 16
Expand All @@ -23,4 +23,4 @@ function cardValidator(ccNumber) {
);
}

module.exports = cardValidator;
module.exports = cardValidator;
18 changes: 9 additions & 9 deletions Sprint-3/revise/implement/get-ordinal-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ function getOrdinalNumber(number) {
const numberAsString = number.toString();

// Helper variable
const exceptions = ["11", "12", "13"];
const exceptions = [11, 12, 13];
const lastDgit = number % 10;
const lastTwoDigits = number % 100;

if (
numberAsString.length > 1 &&
exceptions.includes(numberAsString.slice(numberAsString.length - 2))
) {
if (number > 9 && exceptions.includes(lastTwoDigits)) {
Rashaad-Ebrahim marked this conversation as resolved.
Show resolved Hide resolved
return `${number}th`;
}

switch (numberAsString[numberAsString.length - 1]) {
case "1":
switch (lastDgit) {
case 1:
return `${number}st`;
case "2":
case 2:
return `${number}nd`;
case "3":
case 3:
return `${number}rd`;
default:
return `${number}th`;
}
}

module.exports = getOrdinalNumber;

2 changes: 2 additions & 0 deletions Sprint-3/revise/investigate/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ console.log(find("code your future", "z"));
// c) Why is index++ being used?
// The ++ operator is the increment. It mean to "add 1 to",
// so what index++ does is add 1 to index with each iteration of the while loop.
Rashaad-Ebrahim marked this conversation as resolved.
Show resolved Hide resolved
// The reason for this so that each character of the string can be checked.

// d) What is the condition index < str.length used for?
// It's to ensure that the while loop is not an infinte loop. The loop will run till this condition becomes false.
Rashaad-Ebrahim marked this conversation as resolved.
Show resolved Hide resolved
// The condition checks if index is less than the str.length. Once index is no longer less than str.length, the loop will end.