-
-
Notifications
You must be signed in to change notification settings - Fork 193
London|ITP-September-2025|Mariia Serhiienko|Sprint 1|Implement #896
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
…js and max.test.js
…js and sum.test.js
…pe.js and dedupe.test.js
| } | ||
|
|
||
| const filteredNumericArr = list.filter( | ||
| (el) => typeof el === "number" && Number.isFinite(el) |
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.
According to
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite
isFinite already checks if the element is a number ( typeof el === "number" ).
I like the usage of the method tho.
| const sortedArr = [...filteredNumericArr].sort((a, b) => a - b); | ||
| const middleIndex = Math.floor(sortedArr.length / 2); | ||
|
|
||
| if (sortedArr.length % 2 !== 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.
Why do we need this last logic from 24 to 28 lines?
| (currMax, el) => Math.max(currMax, (String(el).split(".") || "").length), | ||
| 0 | ||
| ); | ||
| const decMultiplier = 10 ** maxDecimalPlaces; |
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 a very robust solution, but too complex for the sake of the learning purposes, could we assume that the max float decimal places are 2 ? as we see in tests ?
|
|
||
| const total = numbers.reduce((acc, el) => acc + el, 0); | ||
|
|
||
| return Math.round((total + Number.EPSILON) * decMultiplier) / decMultiplier; |
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.
Therefore as a consequence of the comment above, we will not need Epsilon here as MathRound will do its work as expected.
Self checklist
Added tests and implemented solution for the fix, implement and refactor sections