Skip to content

London | 26-ITP-May | Vito Moratti | Sprint 1 | Module data groups/sprint1 - #1297

Open
vmoratti wants to merge 18 commits into
CodeYourFuture:mainfrom
vmoratti:Module-Data-Groups/Sprint1
Open

London | 26-ITP-May | Vito Moratti | Sprint 1 | Module data groups/sprint1#1297
vmoratti wants to merge 18 commits into
CodeYourFuture:mainfrom
vmoratti:Module-Data-Groups/Sprint1

Conversation

@vmoratti

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

Completed exercises for Sprint 1 except for stretch, which i didn't have time for.

Questions

Stretch is optional right?

@vmoratti vmoratti added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 26, 2026
Comment thread Sprint-1/fix/median.js Outdated
Comment on lines +21 to +23
if (!Array.isArray(list) || list.length < 2) {
return null;
}

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 can't an array containing one number have a median?

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.

done

Comment thread Sprint-1/implement/dedupe.js Outdated
Comment on lines +2 to +3
let newArr = [];
for (let i = 0; i < arr.length; i++) {

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.

Indentation is off.

Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode,
as recommended in
https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md
?

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 have that installed, sorry, I don't know what happened there.

Comment on lines +26 to +28
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
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 +5 to +6
const filteredList = elements.filter((value) => typeof value === "number");
return Math.max( ...filteredList)}

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 the code on line 5-6 works also when elments.length < 1?

  • What do you expect from the function calls findMax([0, NaN, 1])? Does your function return the value you expected?

Comment on lines +70 to +74
test("given an array with only non-number values, returns -Infinity", () => {
expect(findMax(["apple", null, undefined])).toEqual(-Infinity);
expect(findMax([null, undefined])).toEqual(-Infinity);
expect(findMax(["apple", "banana"])).toEqual(-Infinity);
}); No newline at end of file

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
@@ -1,4 +1,10 @@
function sum(elements) {
let innit = 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 does the name innit mean?

Comment thread Sprint-1/implement/sum.js
@@ -1,4 +1,10 @@
function sum(elements) {
let innit = 0;
const filteredList = elements.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.

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 +7 to 8
return innit;
}

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.

Indentation is off.

Comment on lines +37 to +40
test("given an array with decimal/float numbers, returns the correct total sum", () => {
expect(sum([1.5, 2.5, 3.5])).toEqual(7.5);
expect(sum([-1.5, -2.5, -3.5])).toEqual(-7.5);
});

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.

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

Comment on lines +4 to +5
for (let i of list) {
if (i === target) {

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.

The identifier i is normally used to represent an array index. Could you rename it?

@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 Jul 31, 2026
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