Skip to content

London | 26-ITP-Sep | Bartosz Kawiak | Sprint 1 | Data Groups - #1478

Open
bartoszkawiak wants to merge 10 commits into
CodeYourFuture:mainfrom
bartoszkawiak:data-groups/sprint-1
Open

bartoszkawiak wants to merge 10 commits into
CodeYourFuture:mainfrom
bartoszkawiak:data-groups/sprint-1

Conversation

@bartoszkawiak

Copy link
Copy Markdown

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

Task code

CYF-1071

Changelist

Completed the JavaScript exercises, added tests to check different cases, fixed errors, and refactored some functions to make the code cleaner and easier to read.

@bartoszkawiak bartoszkawiak added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Groups The name of the module. labels Oct 19, 2026
Comment thread Sprint-1/fix/median.js Resolved
Comment thread Sprint-1/implement/max.test.js Resolved
Comment thread Sprint-1/implement/mean.test.js Resolved
Comment thread Sprint-1/implement/mean.test.js Resolved
Comment thread Sprint-1/implement/mean.js Resolved

function calculateFrequency(input) {
let frequency = 0;
const nums = input.trim().split("\n").map(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.

Is it necessary to call trim() on input?

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 would keep .trim() because it prevents an extra 0 from appearing when the file ends with a newline. However, for this particular Advent of Code task, removing .trim() wouldn't change the final sum because adding zero has no effect.

@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 Oct 25, 2026
@bartoszkawiak bartoszkawiak added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Setup Tasks which should be completed first in a sprint and removed Setup Tasks which should be completed first in a sprint labels Nov 7, 2026

@cjyuan cjyuan left a comment •

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.

Changes look good.

Sorry, I missed some code in my previous review.

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.

I forgot to raise this question in my previous review:

What should calculateMean([Infinity, 0, -Infinity]) or calculateMean([0, NaN]) return?
The same also applies to sum().

Comment thread Sprint-1/implement/max.js Outdated
Comment on lines +10 to +18
if (elements.length === 0) {
return -Infinity;
}

if (elements.length === 1) {
return elements[0];
}
const sortedList = elements.toSorted((a, b) => a - b);
return sortedList.at(-1);

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, but there is a more efficient way to find the extreme value in an array without sorting it, as sorting can be a relatively costly operation.

This approach uses a simple loop and works with arrays of any size.

Since finding the maximum or minimum value in an array is a common programming task, could you research how this approach works and then implement it in your code?

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 believe it's sorted now. Thank you for the feedback CJ.

Comment thread Sprint-1/fix/median.js Outdated
}

for (const item of list) {
if (typeof item === "string" || item === null || list.includes(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.

Note: There are many types of non-number values. You could consider instead checking if the value is NOT a number, and optionally excludes NaN and +/- Infinity.

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.

it's fixed now CJ. Thank you

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 7, 2026
@bartoszkawiak bartoszkawiak added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 8, 2026

@cjyuan cjyuan left a comment

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.

Changes look good. Well done!

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

let max = -Infinity;

for (const item of elements) {
if (item > max) {
max = item;
}
}
return max;

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.

Note: The code on lines 14-21 also works when the array is empty.

@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 Nov 8, 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