Skip to content

Sheffield | 26-ITP-Jan | Karim M'hamdi | Sprint 1 | Module-Data-Groups#1029

Open
KKtech06 wants to merge 5 commits intoCodeYourFuture:mainfrom
KKtech06:coursework/sprint-1
Open

Sheffield | 26-ITP-Jan | Karim M'hamdi | Sprint 1 | Module-Data-Groups#1029
KKtech06 wants to merge 5 commits intoCodeYourFuture:mainfrom
KKtech06:coursework/sprint-1

Conversation

@KKtech06
Copy link

@KKtech06 KKtech06 commented Mar 17, 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: I have modified the files and tested them with Jest and got a Pass

Questions

N/A

@KKtech06 KKtech06 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 17, 2026
Copy link
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.

In the "implement" folder, you missed updating the .test.js files accordingly.

@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 19, 2026
@KKtech06 KKtech06 added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 20, 2026
@cjyuan
Copy link
Contributor

cjyuan commented Mar 20, 2026

Function implementations are ok, but the .test.js files are barely modified. Can you implement the Jest tests in those three files?

@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 20, 2026
@KKtech06 KKtech06 added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 21, 2026
@KKtech06
Copy link
Author

Hello CJ i have modified the test.js files and ran them thought Jest and got a Pass for all of the test.js files

Thank you

Comment on lines +54 to +56
test("ignores non-number values and returns the max", () => {
expect(findMax(["hey", 10, "hi", 60, 10])).toBe(60);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

When a string representing a valid numeric literal (for example, "300") is compared to a number,
JavaScript first converts the string into its numeric equivalent before performing the comparison.
As a result, the expression 60 < "300" evaluates to true.

To test if the function can correctly ignore non-numeric values,
consider including a string such as "300" in the relevant test cases.

Comment on lines +61 to +63
test("given only non-number values, returns null", () => {
expect(findMax(["hey", "hi", null, undefined, NaN])).toBe(null);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The test on line 62 make it looks like the function considers null as the max value.

You can also consider treating an array with only non-number values the same as an array with no numbers, and give all arrays containing no numbers the same treatment?

Comment on lines +37 to +39
test("given decimal numbers, returns the correct total", () => {
expect(sum([1.5, 2.5, 3])).toBe(7);
});
Copy link
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

@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 21, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants