Skip to content

London | 26-ITP-JAN | Asha Ahmed | Sprint 1 | Data Groups#1031

Open
ashaahmed7 wants to merge 10 commits intoCodeYourFuture:mainfrom
ashaahmed7:sprint-1
Open

London | 26-ITP-JAN | Asha Ahmed | Sprint 1 | Data Groups#1031
ashaahmed7 wants to merge 10 commits intoCodeYourFuture:mainfrom
ashaahmed7:sprint-1

Conversation

@ashaahmed7
Copy link
Copy Markdown

@ashaahmed7 ashaahmed7 commented Mar 17, 2026

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

Completed the exercises in each directory on Sprint 1

Questions

N/A

@ashaahmed7 ashaahmed7 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 17, 2026
const middleIndex = Math.floor(list.length / 2);
const median = list.splice(middleIndex, 1)[0];
if (!Array.isArray(list)) return null;
const num = list.filter((l) => typeof l === "number").sort((a, b) => a - b);
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 include -Infinity, Infinity, and NaN in the median calculation (and also in the function in implement/sum.js)?

  • Naming convention for variables that stores an array is:

    • Use plural form (e.g. numbers), or
    • Append a suffix Array or List to the name (e.g., numberArray)

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 currently filter values using typeof l === "number", which includes Infinity, -Infinity, and NaN.
However, these values can distort the median calculation (especially NaN, which propagates).

I plan to refine the filter to include only finite numbers using Number.isFinite() for more robust behaviour.

const numbers = list
.filter((l) => Number.isFinite(l))
.sort((a, b) => a - b);

Comment on lines +11 to +13
if (numericElements.length === 0) {
return -Infinity;
}
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.

Should the function preserve this characteristic?
sum(["apple", "banana", 1, 10]) == sum(["apple", "banana"]) + sum([1, 10])

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.

Good question — with the current implementation, this property does not hold because the function returns -Infinity when no numeric values are present.

This causes inconsistencies when combining results (e.g., -Infinity + 11 = -Infinity).

If we want the function to preserve this additive property, it would be better to return 0 when no numeric values are found, since 0 is the neutral element for addition.

I can update the function accordingly depending on the intended behaviour.

if (numericElements.length === 0) {
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.

The spec only mentions "least surprising" value. It is up to you what's that value should be.
I can only provide you with additional info to make informed decision.

@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 19, 2026
@ashaahmed7 ashaahmed7 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 27, 2026
@cjyuan
Copy link
Copy Markdown
Contributor

cjyuan commented Mar 27, 2026

Your explanation sounds good to me.

@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. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 27, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants