London | 26-ITP-Jan | Oussama Mouggal | Sprint 1| Data-Groups#975
London | 26-ITP-Jan | Oussama Mouggal | Sprint 1| Data-Groups#975Oussama-Mouggal wants to merge 7 commits intoCodeYourFuture:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sprint-1/fix/median.js
Outdated
| } | ||
| const numbers = list.filter(val => typeof val === 'number' && !isNaN(val)); | ||
| if (numbers.length === 0) { | ||
| return null; | ||
| } | ||
| numbers.sort((a, b) => a - b); | ||
|
|
||
| const length = numbers.length; |
There was a problem hiding this comment.
Indentation is off.
Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode,
as recommended in
https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md
?
If you have enabled "Format on save" but it is not working, it is likely that you haven't assign a formatter for JS file. This could happen if you have zero or multiple extensions that can format .js file.
If you have installed "Prettier" extension. To assign it as the formatter of JS code, you can try:
- Use "Format document" to format the JS file. Sometimes, VSCode will ask you to choose a formatter, and you can manually select "Prettier".
- Edit
settings.jsonand set Prettier as the default formatter for JS.
See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
There was a problem hiding this comment.
Thanks for your valuable feedback.I fixed it and corrected the indentation in median.js and configured workspace VS Code settings to use Prettier as the default formatter for JavaScript with format-on-save/paste enabled.
| test("given decimal numbers, returns correct total", () => { | ||
| expect(sum([1.5, 2.5, 3.25])).toBe(7.25); | ||
| }); |
There was a problem hiding this comment.
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); // falseCan 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.
Thank you for the feedback.I updated the decimal test in Sprint-1 to use Jest’s floating-point matcher instead of exact equality.
|
Changes look good. Well done. |
Self checklist
I added tests and implemented code and checked code failure in order to pass the npm tests.