Skip to content

WM | May-2025 | Abdullah Saleh | Module-Data-Groups | Sprint1 #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

3bdullah-saleh
Copy link

@3bdullah-saleh 3bdullah-saleh commented Jul 8, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@3bdullah-saleh 3bdullah-saleh added the Needs Review Participant to add when requesting review label Jul 8, 2025
@arun-john arun-john self-requested a review July 18, 2025 10:17
@arun-john arun-john added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Participant to add when requesting review labels Jul 18, 2025
@3bdullah-saleh 3bdullah-saleh added Needs Review Participant to add when requesting review and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 26, 2025
@arun-john arun-john removed their request for review July 29, 2025 15:00
return null;
}
// Filter out non-numeric values (NaN, undefined, etc.)
const numbersOnly = list.filter(item => typeof item === 'number')
Copy link
Contributor

Choose a reason for hiding this comment

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

NaN is a value of type "number".
If you want to also filter out Infinity, consider using Number.isFinute().

Comment on lines +6 to +14
else if (array.length != 0) {
array.forEach(element => {
if (!arrayCopy.includes(element)) {
arrayCopy.push(element);
}
});
return arrayCopy;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation is off. Can you fix it?

Comment on lines +27 to +30
test.todo("Given an array with no duplicates, it return a copy of the original array");
test("Given an array with no duplicates, it return a copy of the original array", () => {
expect(dedupe(["a", "b", "c"])).toEqual(["a", "b", "c"]);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Can remove test.todo(...) since you have implemented the test.

  • The current test code cannot check if the returned array is a copy of the original array because toEqual() compares objects (including arrays) by value. To illustrate,

  const A = [2, 3, 1];
  const B = [...A];          // B is a copy of A
    
  // This set of code cannot distinguish if the compared objects are the same objects.
  expect(A).toEqual(A);  // true
  expect(A).toEqual(B);  // true

In order to check if the returned array is a copy of the original array, we would need additional checks.
Can you find out what code you need to add in order to ensure the returned value is not the original array?

Comment on lines +73 to +77
test("Given an array with only non-number values, should return Infinity", () => {
const input = ['hey', "10", 'hi', "60", "10"]
const output = Infinity
expect(findMax(input)).toEqual(output)
});
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Can your function pass this test?

  • Can you check if the following two function calls return the value you expect?

    findMax(["A"]);
    findMax([NaN, 1, 2, 3]);

Comment on lines +46 to 51
test("Given an array with just negative numbers, should return the closest number to zero", () => {
const input = [-1, -2, -1, -5, -15]
const output = 1
expect(findMax(input)).toEqual(output)
});

Copy link
Contributor

Choose a reason for hiding this comment

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

The largest number in input is -1, not 1.

Comment on lines +39 to 44
test("Given an array with decimal/float numbers, should return the correct total sum", () => {
const input = [1.5, 2.4, 3.5];
const output = 7.4
expect(sum(input)).toEqual(output)
});

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

else if (elements.length > 1) {
const numbersOnly = elements.filter(element => typeof element === 'number');
if (numbersOnly.length == 0) {
return Infinity;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's your rationale to return Infinity when the array does not contain any number?

Comment on lines +58 to +62
test("Given an array with only non-number values, should return Infinity", () => {
const input = ["2.4", "hello", null, undefined];
const output = Infinity
expect(sum(input)).toEqual(output)
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check if your function returns the expected values in the following function calls?

sum(["A"]);
sum([-Infinity, 1, 2, 3]);
sum([-Infinity, Infinity]);
sum([Infinity, 1, 2, 3]);

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jul 30, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants