Skip to content

London | 26-ITP-JAN | Xuanming Hu | Sprint 1 | Data Groups#1007

Open
Samual-Hu wants to merge 2 commits intoCodeYourFuture:mainfrom
Samual-Hu:coursework/sprint-1
Open

London | 26-ITP-JAN | Xuanming Hu | Sprint 1 | Data Groups#1007
Samual-Hu wants to merge 2 commits intoCodeYourFuture:mainfrom
Samual-Hu:coursework/sprint-1

Conversation

@Samual-Hu
Copy link

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 all exercises in the Sprint 1 directory.

Questions

N/A

@Samual-Hu Samual-Hu added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 14, 2026
Comment on lines +6 to +12
const numericElements = elements.filter(item => typeof item === "number");

if (numericElements.length === 0) {
return -Infinity;
}

return Math.max(...numericElements);
Copy link
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?

findMax([NaN])
findMax([0, NaN, 1])

Copy link
Author

@Samual-Hu Samual-Hu Mar 21, 2026

Choose a reason for hiding this comment

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

For findMax([NaN]), I expected -Infinity, but the actual result is NaN.
For findMax([0, NaN, 1]), I expected 1, but the actual result is also NaN.
This is because the type of NaN is number.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the function does not behave the way you expected, why not update the function so that it matches your expectation?

Comment on lines +6 to +14
let total = 0;

for (let i = 0; i < elements.length; i++) {
if (typeof elements[i] === "number") {
total += elements[i];
}
}

return total;
Copy link
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]);

Copy link
Author

Choose a reason for hiding this comment

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

For sum([NaN, 1]), I expected 1, but the actual result is NaN.
For sum([Infinity, -Infinity]), I expected 0, but the actual result is NaN.
This is also because the type of NaN is number.

@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
@Samual-Hu Samual-Hu 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 Mar 21, 2026
@Samual-Hu
Copy link
Author

Hi @cjyuan , Thank you for your comments. I have resolved the indentation issues and conducted additional tests.

@cjyuan
Copy link
Contributor

cjyuan commented Mar 21, 2026

Thanks for the explanations.

Updating the check in max.js and sum.js to filter out NaN should be straight forward.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants