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

London 11 | Pezhman-Azizi | Structuring-and-testing-data | week3 | sprint 3 #214

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Pezhman-Azizi
Copy link

@Pezhman-Azizi Pezhman-Azizi commented Dec 2, 2024

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 COHORT_NAME | FIRST_NAME LAST_NAME | REPO_NAME | WEEK
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

This pull request includes all the core functions and tests needed for Sprint-3. I’ve added a bunch of JavaScript implementations (like handling angles, cards, fractions, triangles, etc.) and wrote tests for everything using Jest. Also updated the package.json to set up testing.

Questions

  1. For rotateCharacter.js, do you think the way I’m handling big negative shifts is solid, or should I try something different?

  2. In passwordValidator.js, the repeated password check uses a fixed list right now—would it make more sense to handle this dynamically somehow?

  3. In countChar.js, the function assumes case sensitivity—should I consider adding an option for case-insensitive searches, or does it overcomplicate things?

@Pezhman-Azizi Pezhman-Azizi added the Needs Review Participant to add when requesting review label Dec 2, 2024
@cjyuan cjyuan self-requested a review December 2, 2024 18:32
Copy link

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

I left my comments and suggestions in the code.

To answer your questions:
Q: For rotateCharacter.js, do you think the way I’m handling big negative shifts is solid, or should I try something different?
A: When you test your function on large negative shift values, does your function return the value you expected?

Q: In passwordValidator.js, the repeated password check uses a fixed list right now—would it make more sense to handle this dynamically somehow?
A: This is just a programming exercise. If something is not specified clearly in the spec, you can make appropriate assumption. So whether to update your password array dynamically is up to you.

In practice, web applications don't save user's passwords in the database.

Q: In countChar.js, the function assumes case sensitivity—should I consider adding an option for case-insensitive searches, or does it overcomplicate things?
A: Up to you. :)

return "invalid angel";
}
}
console.log(getAngleType(180));
Copy link

Choose a reason for hiding this comment

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

Only one test case?

Without using Jest, you can prepare your test as
console.assert(getAngleType(180) === "Right angle", "Right angle");
so that if the function does not return the expected value, you will see the error message "Right angle".

Can you include more test cases to thoroughly test your function? They can help you detect bugs in your code.

}else
return `Invalid card rank.`
}
console.log(getCardValue("K♠"));
Copy link

Choose a reason for hiding this comment

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

What do you expect from the following function calls?
Does your function returns the value you expected?

getCardValue("0Q♠");
getCardValue("010♠");
getCardValue("02♠");
getCardValue("0x02♠");
getCardValue("2.1♠")


if(denominator === 0){
throw new Error("Denominator cannot be zero");
}else if(numerator === denominator){
Copy link

Choose a reason for hiding this comment

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

This test, if (numerator === denominator), is optional. Can you figure out why?

console.log(isProperFraction(4, 0));


console.assert(isProperFraction(2, 3) === true, "2/3 should be a proper fraction");
Copy link

Choose a reason for hiding this comment

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

Could also test negative values in numerator and/or denominator (for cases when |numerator| < |denominator|).


function isValidTriangle(a, b, c){
// Checks if the sides are positive
if (a <= 0 || b <= 0 || c <= 0){
Copy link

Choose a reason for hiding this comment

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

Is it necessary to include the if-statement at lines 42-44?
Can you find any values for a, b, and c, such that the function will fail after you removed the if-statement at lines 42-44?
If you cannot find such a, b, and c, that means you probably do not need that if-statement.

I will not go into details why in some programming languages (but not JavaScript) we need also to check if a, b, c are positives.

The main point I would like to make is, you should fully understand what you wrote in your code. An interviewer may ask you questions like what I am asking here, and it would reflect poorly on you if you cannot explain your code.

count += 1;
}
});

Copy link

Choose a reason for hiding this comment

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

Maybe the spec wasn't clear enough. Usually a function that "count something" would simply return an integer.
I am afraid you may have overdone.

@@ -0,0 +1,21 @@
function getOrdinalNumber(number){

let firstDigit = number%10;
Copy link

Choose a reason for hiding this comment

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

A better practice is to use const instead of let to declare variables which do not change. Such practice could lead to less error prone code.


if(number<=1) return false;

for (let i = 2; i <= number-1; i++) {
Copy link

Choose a reason for hiding this comment

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

To check if number has a factor that can fully divide it, you can check only odd numbers, and only odd numbers less than or equal to square root number.

Doing so can possibly improve the performance of the function.

You can try Google to find out "how to determine if a number is prime efficiently in JS".

let hasNumber = (/\d/.test(password));
let hasSpecialCharacter = (/[!#$%.*&]/.test(password));
let repeated = passwords.includes(password);
console.log(repeated);
Copy link

Choose a reason for hiding this comment

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

This shouldn't be here.

}else if (int === 1 ){
return str;
}else{
return str.repeat(int);
Copy link

Choose a reason for hiding this comment

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

What are the values of str.repeat(1) and str.repeat(0)?

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Dec 2, 2024
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