Skip to content

Manchester | 26-ITP-Jan | Abdu Hassen | Sprint 1| Data-Grouping#1120

Open
Abduhasen wants to merge 5 commits intoCodeYourFuture:mainfrom
Abduhasen:Data-Groups-sprint-1
Open

Manchester | 26-ITP-Jan | Abdu Hassen | Sprint 1| Data-Grouping#1120
Abduhasen wants to merge 5 commits intoCodeYourFuture:mainfrom
Abduhasen:Data-Groups-sprint-1

Conversation

@Abduhasen
Copy link
Copy Markdown

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

-fixing and implementing of data on Javascript using loop,if statement.
-testing code using jest.

Questions

N/A

@Abduhasen Abduhasen added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Groups The name of the module. labels Mar 27, 2026
return null;
}

list = list.filter((value) => typeof value === "number");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you plan to consider also -Infinity, Infinity, and NaN in the median calculation (and in the functions in implement/max.js and implement/sum.js)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

to handle all type of input i changed the filter , using built in method of Number.isFinite(value) can handle all type of values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not apply the change also to findMax() and sum()?

return (list[middleIndex - 1] + list[middleIndex]) / 2;
} else {
const middleIndex = Math.floor(list.length / 2);
const median = list.splice(middleIndex, 1)[0];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use the same syntax you were using on line 24 to access an array element?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i was writing the codes each one by one that why i forgot to combine them and some times little bit confusing putting line of codes together if you have any recommendation of books or techniques that i can read that would be helpful. thank you.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

After the implemented function is working correctly, we should refactor our code to further improve the code. The process involves reviewing the code carefully, and reading code is a skill that takes time to develop (through reading and writing more code).

If you want something to read, you can try https://javascript.info/

@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 31, 2026
@Abduhasen Abduhasen 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 Apr 4, 2026
Comment on lines +26 to +30
test("The function should return a copy of the original array if the array contains no duplicates", () => {
const original = [2, 4, 5, 6, 8];
expect(dedupe(original)).toEqual(original);
expect(dedupe(original)).not.toBe(original);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is a chance that, even though the return value has incorrect elements (for example, [2, 2, 2, 2, 2]),
the two tests could still pass. Can you figure out why, and then fix the tests accordingly?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i did some fixation now it is improved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is not about how many sets of data you are testing, the issue in "how" you carry out the test.

Don't think how you implement your function. Think about under what condition a buggy function that returns [2, 2, 2, 2, 2] can possibly pass the test.

Comment on lines +42 to +48
expect(sum([7.8045, 1.273, 3.19])).toBeCloseTo(12.2675, 4);
expect(sum([4.6, 1.8, 3.18, 5.4])).toBeCloseTo(14.98);
expect(sum([11 / 12, 4 / 6, 1 / 2, 6 / 20])).toBeCloseTo(2.383333, 6);
expect(sum([1 / 2, 2 / 3, 3 / 4, 4 / 5, 5 / 6, 6 / 7])).toBeCloseTo(
4.407142857,
9
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why specify different "number of decimal places" in your tests?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Because the more decimal places I expected value has, the stricter my test needs to be.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just enforce the strictest tolerable difference?

If the function can pass this test
expect(sum([7.8045, 1.273, 3.19])).toBeCloseTo(12.2675, 9);
then the function will also pass
expect(sum([7.8045, 1.273, 3.19])).toBeCloseTo(12.2675, 4);

For adding only a few numbers, the rounding error will be very small. So it's ok to be strict.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ok i will implement that in fact in this test i did that the test go through all the decimal numbers until the end that's why i specified each decimal number to test.

@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 Apr 4, 2026
@Abduhasen Abduhasen 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 Apr 4, 2026
@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 Apr 5, 2026
@Abduhasen Abduhasen 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 Apr 5, 2026
Copy link
Copy Markdown
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.

You have all the info to further improve the code. I will mark this PR as complete first.

Comment on lines +28 to 31
expect(original1.length).toBe(new Set(original1).size);
const result1 = dedupe(original1);
expect(result1).toEqual(original1);
expect(result1).not.toBe(original1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • If their length is different, toEqual() would also fail.

  • Objects (including arrays) are passed to a function by reference, meaning that the they have a chance to be mutated by the function. So on line 30, it is safer to write expect(reuslt1).toEqual('[2,4,5,6,8]').

@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 Apr 5, 2026
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.

2 participants