-
-
Notifications
You must be signed in to change notification settings - Fork 224
London | ITP-Jan-26 | Mohsen Zamani | Sprint 1 | Coursework#949
London | ITP-Jan-26 | Mohsen Zamani | Sprint 1 | Coursework #949mohsenzamanist wants to merge 3 commits intoCodeYourFuture:main from
Conversation
Sprint-1/implement/dedupe.test.js
Outdated
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 should fail if the function returns the original array (instead of a copy of the original array).
The current test checks only if both the original array and the returned array contain identical elements.
In order to validate the returned array is a different array, we need an additional check.
Can you implement this additional check?
Sprint-1/implement/sum.test.js
Outdated
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.
Decimal numbers in most programming languages (including JS) are internally represented in "floating point number" format. Floating point arithmetic is not exact. For example, the result of 46.5678 - 46 === 0.5678 is false because 46.5678 - 46 only yield a value that is very close to 0.5678. Even changing the order in which the program add/subtract numbers can yield different values.
So the following could happen
expect( 1.2 + 0.6 + 0.005 ).toEqual( 1.805 ); // This fail expect( 1.2 + 0.6 + 0.005 ).toEqual( 1.8049999999999997 ); // This pass expect( 0.005 + 0.6 + 1.2 ).toEqual( 1.8049999999999997 ); // This fail console.log(1.2 + 0.6 + 0.005 == 1.805); // false console.log(1.2 + 0.6 + 0.005 == 0.005 + 0.6 + 1.2); // false
Can you find a more appropriate way to test a value (that involves decimal number calculations) for equality?
Suggestion: Look up
- Checking equality in floating point arithmetic in JavaScript
- Checking equality in floating point arithmetic with Jest
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.
That was interesting. Thank you.
And hope I got it right.
cjyuan
commented
Feb 12, 2026
While creating the tests, deleted some of the comments explaining what each test should do, because the description on each test was self-explanatory. Is it a good practice or the original comments must stay?
You can delete the original comments if the same information can be found in the test description.
What is the best practice to add comments? When do comments must be added?
- Don't state the obvious (e.g., if a variable name is self explanatory, then we don't have to repeat the info in a comment)
- Comments should aide others (or yourself in the future) understand the code, or why you did things in a certain way.
- Keep the comments concise
I think ChatGPT can probably give you a more complete suggestion.
@cjyuan
cjyuan
left a comment
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.
Changes look good.
Just the part that checks "if the function returns a copy of the original array" is not quite correct. Can you fix it?
Sprint-1/implement/dedupe.test.js
Outdated
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.
Line 33 does not quite check if the function returns a copy of the original array.
Sprint-1/implement/sum.test.js
Outdated
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.
If the input does not involve decimal numbers, toEqual() is better.
All integers in the interval [-Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER] can be represented precisely.
cjyuan
commented
Feb 13, 2026
Well done!
Learners, PR Template
Self checklist
Changelist
Completed tasks of Sprint 1: fix, implement, refactor, stretch folders
Questions