Repository navigation
Conversation
| // execute the code to ensure all tests pass. | ||
|
|
||
| export function getAngleType(angle) { | ||
| // TODO: Implement this function |
There was a problem hiding this comment.
What do you think happens when a function is declared twice, once at the top and again right inside itself without the inner one ever being called?
There was a problem hiding this comment.
I had to have a read about it and it seems that the function would be redefined inside of itself resulting in the inner function being called instead, but only if it needed to be a recursive one. In this situation, it would look confusing, but would still do the intended job.
However, I think there might have been a misunderstanding with the diff. I only changed the function declaration/export style slightly, so the original declaration in red was replaced by the implementation in green; the function isn't declared twice. I wondered about this because a similar comment was added to another task (implement-isProperFraction) on a function that was also in the deleted code. Could you clarify if I'm missing something?
| // execute the code to ensure all tests pass. | ||
|
|
||
| export function getAngleType(angle) { | ||
| // TODO: Implement this function |
There was a problem hiding this comment.
What happens if someone passes a non-number like "90" or null here? Should we add validation
There was a problem hiding this comment.
Good point. I did not take that into consideration. Passing a regular string would return an "invalid angle", but an empty one or null would not
|
|
||
| // TODO: Write tests to cover all cases, including boundary and invalid cases. | ||
| // Example: Identify Right Angles | ||
|
|
There was a problem hiding this comment.
Should we add tests for zero and negative numbers too, just to check how those boundary cases are handled
| // execute the code to ensure all tests pass. | ||
|
|
||
| export function isProperFraction(numerator, denominator) { | ||
| // TODO: Implement this function |
There was a problem hiding this comment.
Looks like this function is declared twice here. What do you think happens to that inner function since it's never called
There was a problem hiding this comment.
In my 1st version, the one you've commented, I changed the function declaration/export style slightly and if you view the file it's more clear that the function has been declared once
|
|
||
| // TODO: Write tests to cover all cases. | ||
| // What combinations of numerators and denominators should you test? | ||
|
|
There was a problem hiding this comment.
What happens if the denominator is 0? Should we add a test case to see how the function handles that?
| return "invalid"; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Is there any debug logging at the bottom of the file that we should remove before finalizing?
| // execute the code to ensure all tests pass. | ||
|
|
||
| export function getCardValue(card) { | ||
| // TODO: Implement this function |
There was a problem hiding this comment.
Just like the other files, this function is declared twice. What happens to the inner function since it isn't exported or called
| cardRank == "10" | ||
| ) { | ||
| return Number(cardRank); | ||
| } else { |
There was a problem hiding this comment.
The instructions above mention that an invalid card string should throw an error. How does returning the string "invalid" compare to throwing an error
| ) { | ||
| return Number(cardRank); | ||
| } else { | ||
| return "invalid"; |
There was a problem hiding this comment.
What happens to the throw new Error statement right after return "invalid"; on line 57? Will that error ever actually be reached by the program?
| throw new Error(`Expected a number followed by a suit, but got "${card}"`); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Is there any debug logging (console.log) at the bottom of the file that we should remove before finalizing or committing our code?
| // To learn how to test whether a function throws an error as expected in Jest, | ||
| // please refer to the Jest documentation: | ||
| // https://jestjs.io/docs/expect#tothrowerror | ||
| // -----number cards------ |
There was a problem hiding this comment.
GREAT WORK HERE!
but notice how all the number card tests (2 through 9) follow the exact same pattern. Is there a built-in Jest feature (like test.each) we could use here to keep our tests DRY (Do not repeat yourself) and avoid repeating code
dkrest1
left a comment
There was a problem hiding this comment.
Great job working through these! Your logic and test coverage for edge cases and errors are really strong.
Before finalizing, just double-check for:
-
Duplicate function declarations in your implementation files.
-
Leftover debug logs (console.log) that can be removed.
DRY tests (like using test.each for repetitive test cases).
Thanks for sharing your progress, keep up the great work!
Learners, PR Template
Self checklist
Task code
CYF-1059
Changelist
Wrote function implementations and tests in Node and Jest covering a variety of cases.