Glasgow | 25-ITP-SEP | Fares Bakhet | Sprint 1 | Coursework/sprint 1#825
Glasgow | 25-ITP-SEP | Fares Bakhet | Sprint 1 | Coursework/sprint 1#825Fares-Bakhet wants to merge 14 commits intoCodeYourFuture:mainfrom
Conversation
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Sprint-1) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Sprint-1) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
2 similar comments
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Sprint-1) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Sprint-1) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
|
Your PR's title isn't in the expected format. Please check the expected title format, and update yours to match. Reason: Sprint part (Sprint-1) doesn't match expected format (example: 'Sprint 2', without quotes) If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). |
Sprint-1/implement/max.js
Outdated
| if (Math.sign(num) === -1 && num.length > 1) { | ||
| return Math.max(...num); | ||
| } | ||
| if (num.isDecimal === true) { |
Sprint-1/implement/max.js
Outdated
| if (typeof num[i] !== "number") { | ||
| num.splice(i, 1); | ||
| i--; | ||
| } |
There was a problem hiding this comment.
Currently this function may not work for some arrays. For example, when nums is ["A"].
Instead of deleting elements from num (which could be an undesired side effect), consider using .filter() to filter elements that are numbers to a separate array, and then find the largest value in the new array.
Doing so could also simplify the code.
| test("given an array with decimal numbers, returns the correct total sum", () => { | ||
| expect(sum([1.5, 2.5, 3.5])).toBe(7.5); | ||
| }); | ||
|
|
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
| return Math.max(...numbers); | ||
| } | ||
|
|
||
| return arr[arr.length - 1]; |
There was a problem hiding this comment.
This is an odd choice of value to return.
Is there any value you don't expect findMax() to ever return?
Learners, PR Template
Self checklist
Changelist
I have opened this RP after completing the tasks required.
Questions
No questions.