Skip to content

London | 26-ITP-May | Damilola Odumosu | Sprint 1 | Coursework - #1296

Open
d-odumosu wants to merge 10 commits into
CodeYourFuture:mainfrom
d-odumosu:coursework/sprint-1
Open

London | 26-ITP-May | Damilola Odumosu | Sprint 1 | Coursework#1296
d-odumosu wants to merge 10 commits into
CodeYourFuture:mainfrom
d-odumosu:coursework/sprint-1

Conversation

@d-odumosu

Copy link
Copy Markdown

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

Sprint 1 Tasks

fix :

  • median

implement:

  • dedupe

  • max

  • sum

refactor:

  • includes

@d-odumosu d-odumosu added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 1 Assigned during Sprint 1 of this module Module-Data-Groups The name of the module. labels Jul 26, 2026
@cjyuan cjyuan added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jul 31, 2026
Comment thread Sprint-1/fix/median.js Outdated
Comment thread Sprint-1/implement/dedupe.js Outdated
Comment thread Sprint-1/implement/dedupe.test.js
Comment thread Sprint-1/implement/max.js
Comment on lines +8 to +10
if (elementLists.length === 0) {
return undefined;
}

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.

When a function is expected to return a number, it is better to design the function to always returned a value of type number for consistency.

Technically, an empty array also an array containing no numbers.

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.

fixed to return 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.

What's your decision process to select 0 as the return value when an array does not contain any numbers?

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.

since the function is supposed to return a number i thought it best that if the array is empty /contain to numbers it should return 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.

An empty array is also an array containing no numbers. So the function could also return the same value in both cases. However, if the function needs to distinguish an empty array from an array containing no numbers, then your choice would make sense.

Comment thread Sprint-1/implement/max.test.js
Comment thread Sprint-1/implement/sum.js Outdated
Comment thread Sprint-1/implement/sum.js
Comment on lines +11 to +15
let sum = 0;
for (let i = 0; i < elementsList.length; i++) {
sum += elementsList[i];
}
return sum;

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.

Could this code work for an array of any length?

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.

yes, so i think i dont have to check and return 0 if its empty because the loop will do that anyway, thank you, fixed

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.

You also don't have to check if the array length is 1.

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.

yes, removed this

Comment thread Sprint-1/refactor/includes.js
@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 31, 2026
@d-odumosu d-odumosu 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 Aug 21, 2026
Comment on lines 2 to +6
if (elements.length === 0) {
return [];
}

return elements.filter((item, index) => elements.indexOf(item) === index);
return [...new Set(elements)];

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.

Using Set() also works. The point I wanted to make was, checking elements.length === 0 is optional.

testCaseNoDuplicates.forEach(({ input, expected }) => {
test("given an array with no duplicates, return a copy of the array", () => {
expect(dedupe(input)).toEqual(expected);
expect(result).not.toBe(input);

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.

What is result?

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.

result saves the function call of dedeupe

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.

Is result declared and assigned any value?

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.

yes i see the problem now, i have fixed it

Comment thread Sprint-1/implement/max.js
Comment on lines +8 to +10
if (elementLists.length === 0) {
return undefined;
}

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.

What's your decision process to select 0 as the return value when an array does not contain any numbers?

Comment thread Sprint-1/implement/sum.js Outdated
Comment on lines 2 to 8
const elementsList = elements.filter((element) => {
return typeof element === "number";
return (
typeof element === "number" &&
!Number.isNaN(element) &&
Number.isFinite(element)
);
});

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.

Some of the checks are redundant. Could you use AI to research how you could simplify the code on line 2-8?

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.

yes, i have done some research and see that Number.isfinite sufficess

Comment thread Sprint-1/implement/sum.js
Comment on lines +11 to +15
let sum = 0;
for (let i = 0; i < elementsList.length; i++) {
sum += elementsList[i];
}
return sum;

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.

You also don't have to check if the array length is 1.

@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 Aug 21, 2026
@d-odumosu d-odumosu 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 Aug 21, 2026
@cjyuan

cjyuan commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

All good.

@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 Aug 21, 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