Skip to content

Conversation

@i786m
Copy link

@i786m i786m commented Oct 26, 2025

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 implemented the various functions and the associated tests for the functions.

Questions

The instructions for sprint 1 say that the npm install should be run within the sprint 1 folder but when I attempt to use the Testing tab on vscode I am unable to run the tests from within and the output indicates the tests fail to run as it seems to be looking in the root folder for the node module for jest. I was able to run the tests using npm test however the testing functionality afforded by vscode was diminished by that. Could there be a better way of doing this?

@i786m i786m added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 26, 2025
@i786m
Copy link
Author

i786m commented Oct 26, 2025

image I enclose a screenshot to demonstrate the error returned pertinent to the question I asked when initially opening this PR

Comment on lines +18 to +37
if(filteredList.length === 0) {
return null;
}

//sort the filtered list
filteredList.sort((a, b) => a - b);

const isEven = filteredList.length % 2 === 0;

if(isEven ){
const mid1 = filteredList.length / 2 - 1;
const mid2 = mid1 + 1;
const median = (filteredList[mid1] + filteredList[mid2]) / 2;
return median
}else {
const mid = Math.floor(filteredList.length / 2);
const median = filteredList[mid];
return median;
};

Copy link
Contributor

Choose a reason for hiding this comment

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

To more consistently format the code, consider using this VSCode built-in feature to auto format the code: https://code.visualstudio.com/docs/languages/javascript#_formatting

Comment on lines +27 to +29
test("given an array with no duplicates, it returns a copy of the original array", () => {
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.

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 +37 to +39
test("given an array with decimal numbers, returns correct sum",()=>{
expect(sum([1.5,2.5,3.5])).toBe(7.5);
})
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 Nov 8, 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 with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants