Skip to content

Sheffield | 26-ITP-jan | Richard Frimpong | Sprint 1 | Data Groups#1032

Open
Richiealx wants to merge 7 commits intoCodeYourFuture:mainfrom
Richiealx:coursework/sprint-1-data-groups
Open

Sheffield | 26-ITP-jan | Richard Frimpong | Sprint 1 | Data Groups#1032
Richiealx wants to merge 7 commits intoCodeYourFuture:mainfrom
Richiealx:coursework/sprint-1-data-groups

Conversation

@Richiealx
Copy link

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 contains my completed work for Sprint 1 - Data Groups.

Fix

Completed the fix exercise by correcting the implementation of:

  • Sprint-1/fix/median.js

Changes made:

  • fixed the median calculation
  • handled both odd and even length arrays correctly
  • filtered out non-numeric values
  • returned null when no numeric values are present
  • avoided mutating the original input array

Implement

Completed the implement exercises by implementing the required functions in:

  • Sprint-1/implement/sum.js
  • Sprint-1/implement/max.js
  • Sprint-1/implement/dedupe.js

I also completed the related test files:

  • Sprint-1/implement/sum.test.js
  • Sprint-1/implement/max.test.js
  • Sprint-1/implement/dedupe.test.js

Implemented functionality includes:

  • sum - calculates the total of numeric values in an array while ignoring non-numeric elements
  • findMax - returns the largest numeric value in an array while ignoring non-numeric elements
  • dedupe - removes duplicate values from an array while preserving the first occurrence

Refactor

Completed the refactor exercise by updating:

  • Sprint-1/refactor/includes.js

Changes made:

  • replaced the indexed for loop with a for...of loop
  • simplified the implementation while keeping the same behaviour
  • confirmed the function still correctly checks whether the target value exists in the array

Testing

All tests were run locally using:

cd Sprint-1
npm test -- fix
npm test -- implement
npm test -- refactor

@Richiealx Richiealx 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.

Code is good. I only have a few suggestions.

Comment on lines 23 to +28
// Given an array with no duplicates
// When passed to the dedupe function
// Then it should return a copy of the original array
test("given an array with no duplicates, it returns the same values", () => {
expect(dedupe([1, 2, 3])).toEqual([1, 2, 3]);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This test should fail if the function returns the original array (instead of a copy of the original array).

The current test checks only if both the original array and the returned array contain identical elements.
In order to validate the returned array is a different array, we need an additional check.

Can you find out what this additional check is?

Comment on lines +53 to +55
test("given an array with non-number values, ignores them 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 20 < "300" evaluates to true.

To test if the function can correctly ignore non-numeric values, you could include a string such as "300" in the test cases.

Comment on lines +37 to +39
test("given an array with decimal numbers, returns the correct sum", () => {
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

Copy link
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 the feedback.

I have updated the code and tests based on your comments:

  • removed the unnecessary extra array clone in median.js
  • improved the dedupe test so it checks that the returned array is a different array object
  • updated the max test to include a numeric string such as "300" to confirm non-number values are ignored
  • changed the decimal sum test to use toBeCloseTo(...) for floating-point comparison
  • updated sum.js and max.js to use Number.isFinite(...) for stricter numeric checks
  • fixed the dedupe.js export so the implement tests run correctly

I re-ran all Sprint 1 test suites and all tests are passing.

Copy link
Contributor

Choose a reason for hiding this comment

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

All these changes sounds good, but your actions somehow introduced merge conflicts to the files. Can you resolve the conflicts?

@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
@Richiealx Richiealx added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 19, 2026
Comment on lines +14 to +26
<<<<<<< HEAD
// Keep only real numeric values
const numbersOnly = list.filter(
(item) => typeof item === "number" && !Number.isNaN(item)
);

// Return null if the array contains no numbers
=======
// filter() returns a new array, so this does not modify the original input
const numbersOnly = list.filter((item) => Number.isFinite(item));

// Return null if there are no numeric values
>>>>>>> a22ed15 (Address mentor feedback for sprint 1 data groups)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a unresolved merge conflict. You need to delete the "merge conflict markers" and the code that you do not want to keep.

There are several others on the files in this branch.

Can you fix them?

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 19, 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