-
-
Notifications
You must be signed in to change notification settings - Fork 195
WM | May-2025 | Abdullah Saleh | Sprint-3 #627
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?
WM | May-2025 | Abdullah Saleh | Sprint-3 #627
Conversation
…rs are numeric also create some test cases
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.
Always validate input types (string/number) when writing functions that expect numbers.
function isProperFraction(numerator, denominator) {
if (denominator === 0) return "Undefined";
else if (numerator < denominator) return true;
else return false;
}
``` check the type of input variable
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 is generally looking really good, but I left a few comments of things to think about.
I haven't reviewed the card validator yet, I'll take a look later today, but wanted to leave you some comments you can work on in the mean time!
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.
Your card number validator is looking good too, though I left a few comments to consider as well! I'm glad you attempted it, doing the stretch work is really useful for learning!
if (cardNumber.length !== 16) { | ||
return false; | ||
} | ||
const numberInArray = cardNumber.toString().split(""); // convert the cardNumber to sting then into an array |
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.
It's interesting that you check its length and then convert it to a string. What type do you think cardNumber
may have which has a .length
property, but isn't a string?
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 originally thought this was an edge case to handle, but it turned out not to be a good approach — even my test tricked me by passing.
The reason the test passed is because cardNumber.length was undefined, so the condition undefined !== 16 returned true, leading to a false return value that matched the expected outcome.
I later got advice from AI that JavaScript rounds numbers longer than 15 digits, so it's always better to pass long numbers like card numbers as strings.
Just to confirm — I’m planning to remove the .toString() call from my function, since the cardNumber will always be passed as a string.
…er return values.
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 is all looking good - I'll mark this as Complete, but I've left a couple of interesting questions to ponder :)
function repeat(str, count) { | ||
if (count > 0) return `${str.repeat(count)}`; | ||
else if (count == 0) return ""; | ||
else if (count < 0) return "negative counts are not valid"; |
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 think about returning a string here vs throwing an error? With the fraction with denominator of 0 you decided to throw - is there a reason to prefer one or the other 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.
You're right — there's no strong reason for treating them differently.
It would be more consistent to throw an error for invalid input like a negative count, just as I did with the zero denominator case.
else if (rank >= 2 && rank <= 9) return Number(rank); | ||
else if (rank === 10 || rank === "J" || rank === "Q" || rank === "K") return 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.
You could have handled 10 in the "If a number" case or the "J/Q/K" case (both of which work). Why did you decide to choose the approach you did? What benefits/drawbacks does each have?
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.
Actually, I handled it that way because I was following the structure of the test cases. I assumed that 10 could be treated as part of the numeric range and added to the first condition, rather than grouping it with the string values like "J", "Q", or "K".
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.