Skip to content

Conversation

@Iswanna
Copy link

@Iswanna Iswanna commented Nov 10, 2025

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 pull request includes modifications to three directories:

Fix directory: I updated the function implementation so that it passes all test cases.

Implement directory: I added test cases based on the provided scenarios and implemented the function to handle all of them.

Refactor directory: I refactored the existing function implementation, ensuring it continues to pass all test cases.

Questions

Hi. Please could you review my PR? I’d really appreciate your feedback.

This implementation handles arrays with an odd length.
- Adjusted indentation and arrow function formatting
- Added consistent line breaks and spacing
- No changes to test logic or order
… occurrence for arrays of strings and numbers
@Iswanna Iswanna added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Groups The name of the module. 📅 Sprint 1 Assigned during Sprint 1 of this module labels Nov 10, 2025
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.

Can you check if any of this general feedback can help you further improve your code?
https://github.com/CodeYourFuture/Module-Data-Groups/blob/sprint-1-feedback/Sprint-1/feedback.md

Doing so can help reviewers speed up the review process. Thanks.

@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 Nov 20, 2025
@Iswanna
Copy link
Author

Iswanna commented Nov 20, 2025

Can you check if any of this general feedback can help you further improve your code? https://github.com/CodeYourFuture/Module-Data-Groups/blob/sprint-1-feedback/Sprint-1/feedback.md

Doing so can help reviewers speed up the review process. Thanks.

Hi @cjyuan, thank you for sharing the general feedback. I’ll check it against my changes to see whether I’m on the right track.

- Replaced `const copyArray = validNumbers.slice(); const sortArray = copyArray.sort(...)`
  with `const sorted = [...validNumbers].sort(...)`.
- Created a shallow copy and sorts in one step.
- Eliminated redundant `copyArray` variable while keeping original array intact.
- Added `expect(result).not.toBe(input)` to tests that check array output.
- Confirms that the returned array is a new object, not the same reference as the input.
- Maintains `toEqual` checks for content correctness.
- Addresses feedback about verifying array copy vs original reference.
- Replaced `toBe` with `toBeCloseTo` for all tests involving decimal numbers.
- Ensures floating-point sums are tested correctly despite precision issues.
- Updated expected values to match actual sums when necessary (e.g., -7.4 instead of -7.399).
- Keeps integer and exact sums using `toBe`.
@Iswanna
Copy link
Author

Iswanna commented Nov 20, 2025

Can you check if any of this general feedback can help you further improve your code? https://github.com/CodeYourFuture/Module-Data-Groups/blob/sprint-1-feedback/Sprint-1/feedback.md
Doing so can help reviewers speed up the review process. Thanks.

Hi @cjyuan, thank you for sharing the general feedback. I’ll check it against my changes to see whether I’m on the right track.

Hi @cjyuan. I have made changes to some files based on the general feedback you shared. Thank you.

@Iswanna Iswanna 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 Nov 20, 2025
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.

Tests are very comprehensive! I am impressed.


// Create a shallow copy of `validNumbers` and sort it in ascending order
// This avoids modifying the original array
const sorted = [...validNumbers].sort((a, b) => a - b);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to clone validNumbers before sorting?

Copy link
Author

Choose a reason for hiding this comment

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

Do we need to clone validNumbers before sorting?

I have gone through the code and I can see that I do not need to clone validNumbers before sorting. I can mutate validNumbers directly since it is already a new array created by .filter(). I have updated the code with these changes.

Comment on lines +23 to +25
const result = dedupe(input);
expect(result).toEqual(expected);
expect(result).not.toBe(input); // ensures it's a new array
Copy link
Contributor

Choose a reason for hiding this comment

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

Nicely done.

Copy link
Author

Choose a reason for hiding this comment

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

Nicely done.

Thank you.

// Then it should return the least surprising value given how it behaves for all other inputs
test("given an array with only non-number values", () => {
expect(findMax(["a", null, undefined])).toBe(-Infinity);
expect(findMax([{}, [], "hi"]));
Copy link
Contributor

Choose a reason for hiding this comment

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

Something is missing here

Copy link
Author

Choose a reason for hiding this comment

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

Something is missing here

Thank you for pointing this out. I need to complete the test by adding the expected value.

for (const item of filteredElements) {
sumElements += item;
}
return Number(sumElements.toFixed(2));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why limit the result to only two decimal places?

Copy link
Author

Choose a reason for hiding this comment

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

Why limit the result to only two decimal places?

I used toFixed(2) earlier as a workaround for floating-point precision issues when the tests were using toBe, which checks for exact equality.
By rounding to two decimals, I could ensure the returned value matched the expected 0.44 style values.

Now that the tests use toBeCloseTo, the function no longer needs to round the result at all.
toBeCloseTo correctly handles floating-point precision, so I will remove the toFixed(2) rounding and return the raw sum.

Thank you for pointing this out, @cjyuan.

@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 Nov 20, 2025
@Iswanna
Copy link
Author

Iswanna commented Nov 20, 2025

Tests are very comprehensive! I am impressed.

Thank you, @cjyuan.

- Remove redundant cloning of validNumbers before sorting
- Allow safe in-place sort since validNumbers is newly created from list
- Update comments to allign with changes
@Iswanna Iswanna 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 Nov 20, 2025
@Iswanna Iswanna requested a review from cjyuan November 20, 2025 15:22
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.

Changes look good. Well done!


// Create a shallow copy of `validNumbers` and sort it in ascending order
// This avoids modifying the original array
const sorted = [...validNumbers].sort((a, b) => a - b);
Copy link
Contributor

Choose a reason for hiding this comment

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

If you find sorted a more meaningful name for the array, you can also introduce it as

const sorted = validNumbers.sort((a, b) => a - b);

sumElements += item;
}
return Number(sumElements.toFixed(2));
return Number(sumElements);
Copy link
Contributor

Choose a reason for hiding this comment

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

sumElements is already a number.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 20, 2025
@Iswanna
Copy link
Author

Iswanna commented Nov 20, 2025

Changes look good. Well done!

Thank you so much @cjyuan for making the time to review my code and give detailed feedback. I really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Data-Groups The name of the module. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants