Skip to content

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

Open
d-odumosu wants to merge 6 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 6 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
Comment on lines +12 to +13
const arrCopy = [...list];
const filteredNumbers = arrCopy.filter((num) => Number.isFinite(num));

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.

.filter() returns a new array without mutating the original array, there is no need to clone another array.

Comment on lines +2 to +6
if (elements.length === 0) {
return [];
}

return elements.filter((item, index) => elements.indexOf(item) === index);

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 we expect line 6 to work also when array length is 0?

Comment on lines +37 to +39
test("given an array with no duplicates, return a copy of the array", () => {
expect(dedupe(input)).toEqual(expected);
});

@cjyuan cjyuan Jul 31, 2026

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.

Your function implementation is correct. However, this test could be improved to better ensure
that any future changes continue to align with the expected behavior described on line 25:

Then it should return a copy of the original array

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

Comment on lines +98 to +102
const testCaseArrayWithOnlyNonNumberValues = [
{ input: ["hello", "world"], expected: undefined },
{ input: [null, undefined, true, false], expected: undefined },
{ input: [{}, [], "test"], expected: 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 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,
consider including a string such as "300" in the relevant test cases.

Comment thread Sprint-1/implement/sum.js
Comment on lines +5 to +7
const elementsList = elements.filter((element) => {
return typeof element === "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.

What do you expect from the following function calls (on extreme cases)?
Does your function return the value you expected?

sum([NaN, 1]);
sum([Infinity, -Infinity]);

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?

Comment on lines -4 to -5
for (let index = 0; index < list.length; index++) {
const element = list[index];

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.

Your code works.

However, to find if an element exists in an array, the function could stop searching the array as soon as it finds a match; it doesn't necessary need to always search the whole array.

Could you improve your implementation? (You could also just modify two lines of the original code.)

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Data-Groups The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants