Skip to content

Glasgow | ITP May -25 | Pandi Simatupang | Module-Structuring-and-Testing-Data | coursework/sprint-3 #651

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 13 commits into
base: main
Choose a base branch
from

Conversation

PandiSimatupang
Copy link

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Answers and comments to sprint-3

Questions

Ask any questions you have for your reviewer.

@PandiSimatupang PandiSimatupang added the Needs Review Participant to add when requesting review label Jul 10, 2025
@YoanHlebarov YoanHlebarov added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Jul 12, 2025
Copy link

@YoanHlebarov YoanHlebarov left a comment

Choose a reason for hiding this comment

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

The code is correct but it can be improved in terms of performance (doing many checks before returning instead of returning short whenever a check fails) and readability. Think how you can improve the code, is there a way you can write things that are easier to read?

Comment on lines 10 to +16
function getAngleType(angle) {
if (angle === 90) return "Right angle";
// read to the end, complete line 36, then pass your test here
if (angle === 90) return "Right angle";
else if (angle === 180) return "Straight angle";
// 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 return "Reflex angle";

Choose a reason for hiding this comment

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

Here you don't need to write an if elseif statement. When you return short like this. you can simply write if statements each line. Another approach is to use switch.

Comment on lines 10 to +14
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
if (numerator === 0 || denominator === 0) return false;
else if (numerator === denominator) return false;
else if (Math.abs(numerator) < Math.abs(denominator)) return true;
else if (Math.abs(numerator) > Math.abs(denominator)) return false;

Choose a reason for hiding this comment

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

Same as above.

Comment on lines 10 to 20
function getCardValue(card) {
if (rank === "A") return 11;
let rank = card.slice(0, -1); //start from 0 until just before one last character
if (rank === "A") return 11;
else if ((rank === "10") | (rank === "J") | (rank === "Q") | (rank === "K"))
return 10;
else if (rank > 1 && rank < 10)
return Number(
rank
); //need to convert to number, because === compare type and exact number
else return null;
}

Choose a reason for hiding this comment

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

Same as above.

Comment on lines +4 to 9
else if (angle === 180) return "Straight angle";
// 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 return "Reflex angle";
}

Choose a reason for hiding this comment

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

Same as above.

Comment on lines 1 to 9
function isProperFraction(numerator, denominator) {
if (numerator < denominator) return true;
// add your completed function from key-implement here
//if (numerator < denominator) return true;
// add your completed function from key-implement here

if (numerator === 0 || denominator === 0) return false;
else if (numerator === denominator) return false;
else if (Math.abs(numerator) < Math.abs(denominator)) return true;
else if (Math.abs(numerator) > Math.abs(denominator)) return false;
}

Choose a reason for hiding this comment

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

Same as above.

Comment on lines +5 to +15
if (myNum < 10) {
if (myNum === "1") return `${num}st`;
else if (myNum === "2") return `${num}nd`;
else if (myNum === "3") return `${num}rd`;
else return `${num}th`;
} else if (myNum >= 10) {
if (myNumLastChar === "1") return `${num}st`;
else if (myNumLastChar === "2") return `${num}nd`;
else if (myNumLastChar === "3") return `${num}rd`;
else return `${num}th`;
}

Choose a reason for hiding this comment

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

Same as above.

Comment on lines +1 to +7
function repeat(str, rep) {
myStr = "";
for (let i = 0; i < rep; i++) {
myStr = myStr + str;
}
if (rep < 0) return "negative counts are not valid";
return myStr;

Choose a reason for hiding this comment

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

Suggested change
function repeat(str, rep) {
myStr = "";
for (let i = 0; i < rep; i++) {
myStr = myStr + str;
}
if (rep < 0) return "negative counts are not valid";
return myStr;
function repeat(str, rep) {
if (rep < 0) return "negative counts are not valid";
myStr = "";
for (let i = 0; i < rep; i++) {
myStr = myStr + str;
}
return myStr;

You should always be validating your inputs first, that way there are no dubious values being passed down your program which can create a problem. In this case you should check first that the count is a positive integer, before running any other part of your function.

Comment on lines 17 to +31
function passwordValidator(password) {
return password.length < 5 ? false : true
}
let arr = password.split("");
// - Have at least 5 characters.
if (arr.length < 5) return false;
// - Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&")
const symbols = new Array("!", "#", "$", "%", ".", "*", "&");

const hasSymbol = arr.some((char) => symbols.includes(char));
const hasDigit = arr.some((char) => /[0-9]/.test(char));
const hasLower = arr.some((char) => /[a-z]/.test(char));
const hasUpper = arr.some((char) => /[A-Z]/.test(char));

const usedPass = !usedPasswords.includes(password);
return hasSymbol && hasDigit && hasLower && hasUpper && usedPass;
}

Choose a reason for hiding this comment

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

I would consider moving the check if password is used near the top of the function. Similar to the comment above, to check if it is in the usedPasswords list is simple and should be done first, as if it is then the password cannot be used. In your implementation we are doing all checks and then deciding whether the password can be used or not. Consider if using similar approach to other exercises form the module can be used here (eg return short if a check fails).

@YoanHlebarov YoanHlebarov added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed Volunteer to add when completing a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants