-
-
Notifications
You must be signed in to change notification settings - Fork 195
London 11 | Pezhman-Azizi | Structuring-and-testing-data | week3 | sprint 3 #214
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?
Conversation
There was a problem hiding this 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. :)
Sprint-3/implement/get-angle-type.js
Outdated
return "invalid angel"; | ||
} | ||
} | ||
console.log(getAngleType(180)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing out the importance of multiple test cases! I'll add more test cases to thoroughly test my getAngleType function and include error messages using console.assert to ensure the function behaves as expected under different scenarios.
Sprint-3/implement/get-card-value.js
Outdated
}else | ||
return `Invalid card rank.` | ||
} | ||
console.log(getCardValue("K♠")); |
There was a problem hiding this comment.
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♠")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I analyzed the behavior of my function with these inputs and ensure it handles unexpected or invalid card ranks correctly. I'll also update the code to include validation for these edge cases
|
||
if(denominator === 0){ | ||
throw new Error("Denominator cannot be zero"); | ||
}else if(numerator === denominator){ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the insight! I understand that the if (numerator === denominator) condition is optional since dividing a number by itself will always return 1. I'll consider removing it to streamline the logic unless there's a specific need to handle this case differently.
console.log(isProperFraction(4, 0)); | ||
|
||
|
||
console.assert(isProperFraction(2, 3) === true, "2/3 should be a proper fraction"); |
There was a problem hiding this comment.
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|).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expanded the test cases to include scenarios where either the numerator, the denominator, or both are negative, ensuring that the function handles these properly.
|
||
function isValidTriangle(a, b, c){ | ||
// Checks if the sides are positive | ||
if (a <= 0 || b <= 0 || c <= 0){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I now realize that the positivity check for a, b, and c might be unnecessary if the triangle inequality checks inherently ensure valid positive side lengths. I'll review the logic to determine if this check is redundant and ensure I can fully explain my reasoning.
count += 1; | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code to replace let with const for firstDigit and secondDigit since their values remain constant. I've also retained let for suffix as its value changes conditionally. Additionally, I included more test cases to ensure the function handles edge scenarios correctly. Please let me know if there's anything else you'd like me to improve!
|
||
if(number<=1) return false; | ||
|
||
for (let i = 2; i <= number-1; i++) { |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback! I've optimized the isPrime function to improve its efficiency. Instead of checking all numbers up to number - 1, the function now only checks odd numbers up to the square root of the input. I also added early returns for small numbers and numbers divisible by 2 or 3. These changes reduce unnecessary iterations and make the function faster, especially for larger inputs. Let me know if there's anything else you'd like me to adjust!
let hasNumber = (/\d/.test(password)); | ||
let hasSpecialCharacter = (/[!#$%.*&]/.test(password)); | ||
let repeated = passwords.includes(password); | ||
console.log(repeated); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my code now directly evaluates and returns the result without extraneous output. Please let me know if there are any other areas for improvement!
}else if (int === 1 ){ | ||
return str; | ||
}else{ | ||
return str.repeat(int); |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values for str.repeat(1) and str.repeat(0) are straightforward: str.repeat(1) returns the original string, and str.repeat(0) returns an empty string. With this in mind, I can simplify the logic in the function by directly using str.repeat(int) for these cases
- Added validation to check both card rank and suit against predefined valid values. - Improved error handling for invalid inputs like "0Q♠", "02♠", and similar cases. - Expanded test cases to cover valid and invalid scenarios thoroughly using console.assert. - Ensured the function remains robust for unexpected input formats.
- Enhanced logic to use absolute values for comparing numerator and denominator. - Added test cases to handle negative numerator, negative denominator, and both negative scenarios. - Ensured the function works correctly for all proper and improper fraction cases.
- Removed explicit checks for non-positive sides, as triangle inequality naturally ensures validity. - Added comprehensive test cases, including zero, negative, and edge conditions. - Improved function readability and efficiency.
… simplify logic - Modified function to leave non-letter characters (numbers, symbols, spaces) unchanged as per specification. - Simplified wraparound logic for ASCII values of uppercase and lowercase letters. - Added test cases for non-alphabetic characters and large/negative shift values. - Enhanced code readability and alignment with feedback.
- Replaced let with const for variables that do not change (firstDigit, secondDigit). - Retained let for suffix as its value changes conditionally. - Added additional test cases to verify correctness for edge cases. - Improved code readability and reduced potential errors.
- Improved efficiency by limiting checks to odd numbers up to the square root of the input. - Added early returns for small numbers and numbers divisible by 2 or 3. - Reduced unnecessary iterations to improve performance for large inputs. - Added test cases for various edge scenarios.
Learners, PR Template
Self checklist
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
For rotateCharacter.js, do you think the way I’m handling big negative shifts is solid, or should I try something different?
In passwordValidator.js, the repeated password check uses a fixed list right now—would it make more sense to handle this dynamically somehow?
In countChar.js, the function assumes case sensitivity—should I consider adding an option for case-insensitive searches, or does it overcomplicate things?