Skip to content

London | 26-ITP-Jan | Angela McLeary | Sprint 1 | Sprint 1#1129

Open
AngelaMcLeary wants to merge 18 commits intoCodeYourFuture:mainfrom
AngelaMcLeary:Sprint-1
Open

London | 26-ITP-Jan | Angela McLeary | Sprint 1 | Sprint 1#1129
AngelaMcLeary wants to merge 18 commits intoCodeYourFuture:mainfrom
AngelaMcLeary:Sprint-1

Conversation

@AngelaMcLeary
Copy link
Copy Markdown

@AngelaMcLeary AngelaMcLeary commented Mar 28, 2026

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

This PR is about fixing median.js, Implementing dedupe.js, max.js, sum.js and refactoring include.js.

@github-actions

This comment has been minimized.

@AngelaMcLeary AngelaMcLeary added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 28, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 28, 2026
@AngelaMcLeary AngelaMcLeary added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 28, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 28, 2026
@AngelaMcLeary AngelaMcLeary added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. NotCoursework Not coursework - used for curriculum development work. labels Mar 28, 2026
@AngelaMcLeary AngelaMcLeary changed the title London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Coursework/Sprint 1 London | 26-ITP-Jan | Angela McLeary | Sprint 1 | Coursework/Sprint 1 Mar 28, 2026
@AngelaMcLeary AngelaMcLeary changed the title London | 26-ITP-Jan | Angela McLeary | Sprint 1 | Coursework/Sprint 1 London | 26-ITP-Jan | Angela McLeary | Sprint 1 | Sprint 1 Mar 28, 2026
@AngelaMcLeary AngelaMcLeary removed the NotCoursework Not coursework - used for curriculum development work. label Mar 29, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 29, 2026
@AngelaMcLeary AngelaMcLeary added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 29, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 29, 2026
@github-actions

This comment has been minimized.

@AngelaMcLeary AngelaMcLeary added the NotCoursework Not coursework - used for curriculum development work. label Mar 29, 2026
@AngelaMcLeary AngelaMcLeary added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed NotCoursework Not coursework - used for curriculum development work. labels Mar 29, 2026
Comment on lines +37 to +39
test("given an array with decimal float numbers, it should return the total sum", () => {
expect(sum([1.5, 2.5, 3.5])).toEqual(7.5);
});
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cjyuan, Thank you for your feedback. I understand now why decimal values need special handling. toBeCloseTo() is a better choice because it checks that the result is close enough within a small margin, which avoids issues caused by floating‑point rounding.

Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The default value of the second parameter of toBeCloseTo() is only 2
See: https://jestjs.io/docs/expect#tobeclosetonumber-numdigits

For the default value 2, the test criterion is Math.abs(expected - received) < 0.005, which may not be precise enough in some applications.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 31, 2026
@AngelaMcLeary AngelaMcLeary added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Apr 6, 2026
@AngelaMcLeary AngelaMcLeary added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 6, 2026
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other changes are good. Just one issue left.

Comment on lines +28 to +30
const result = dedupe(originalArray);
expect(result).toEqual(originalArray);
expect(result).not.toBe(originalArray);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can verify the function can return a different array.

However, there is a chance that, even though result has incorrect elements (for example, [1, 1, 1]),
the test on line 29 could still pass. Can you figure out why, and then improve the test accordingly?

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants