Skip to content

London | 26-ITP-Sep | Russom Gebremeskel | Sprint 1 | Coursework - #1506

Open
russom-g wants to merge 44 commits into
CodeYourFuture:mainfrom
russom-g:coursework/sprint-1-current
Open

russom-g wants to merge 44 commits into
CodeYourFuture:mainfrom
russom-g:coursework/sprint-1-current

Conversation

@russom-g

@russom-g russom-g commented Nov 8, 2026

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

Fix, refactor and implement code. Write test cases for the program.

@russom-g russom-g added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 8, 2026
Comment on lines +4 to +12
if (list.length === 0) {
return [];
}

for (const item of list) {
if (!elements.includes(item)) {
elements.push(item);
}
}

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 loop also works for empty array.

Comment thread Sprint-1/implement/dedupe.test.js Resolved
Comment on lines +34 to +38
test("given an empty array [], returns Could not calculate a median", () => {
const list = [];
const result = describeMedian(list);
expect(describeMedian(list)).toEqual(result);
});

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 tests in this file could not yet correctly check whether the function could return the expected value.

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.

Updated the test with duplicated elements in the array.

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.

Still have the same issue. AI also identified this bug.

}
total = total + item;
}
return Number(total.toFixed(2)) / list.length;

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 limit the mean to only two decimal places?

Comment thread Sprint-1/implement/mean.test.js Resolved
Comment thread Sprint-1/implement/mean.test.js Outdated
// When passed to calculateMean
// Then it should throw Error("calculateMean requires an array of numbers")
test("given a non-array, returns, calculateMean requires an array of numbers", () => {
expect(() => calculateMean("banana", 42, null, {})).toThrow(

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.

In this function call, calculateMean("banana", 42, null, {}), only the first argument is passed to the function, the rest of them are ignored.

Suggestion:

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.

Test rewritten in a separate expect()

Comment thread Sprint-1/implement/sum.js Outdated
}
total += element;
}
return Number(total.toFixed(2));

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 limit the result to only two decimal places?

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.

The result looked more cleaner. I didn't realise how floating point numbers are calculated.

Now expected value is typed as the calculation.

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 should sum([Infinity, 0, -Infinity]) or sum([0, NaN]) return?
The same also applies to calculateMean().

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.

Test changed to separate expect()

@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 Nov 10, 2026
@russom-g russom-g 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 Nov 25, 2026
try {
return `The median is ${calculateMedian(list)}`;
} catch (error) {
return `Could not calculate a median: calculateMedian requires a non-empty array: ${error.message}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What exact sentence does this return when calculateMedian throws the empty-array error, compared with the example in the acceptance criteria?

To "like" or "dislike" this comment, please follow this link

expect(() => sum([null])).toThrow(
new Error("sum requires an array of numbers")
);
expect(() => sum([3])).toThrow(new Error("sum requires an array of numbers"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These assertions expect sum([3]) to throw, so the suite fails for a valid array of numbers. The purported non-array test repeats array inputs instead of checking a non-array.

To "like" or "dislike" this comment, please follow this link

}
total = total + item;
}
return Number(total.toFixed(2)) / list.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens to the mean of values with more than two decimal places when the total is rounded before dividing?

To "like" or "dislike" this comment, please follow this link

test("given [1, 2, 3], returns The median is 2", () => {
const list = [1, 2, 3];
const result = describeMedian(list);
expect(describeMedian(list)).toEqual(result);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What incorrect sentence would either of these assertions catch if describeMedian returned the wrong result?

To "like" or "dislike" this comment, please follow this link

Comment on lines +44 to +45
const list = [];
const result = describeMedian(list);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this test pass a non-array value to describeMedian?

To "like" or "dislike" this comment, please follow this link

// When passed to calculateMean
// Then it should return that number
test("given [6], returns 6", () => {
expect(6).toEqual(6);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What function call is this assertion checking?

To "like" or "dislike" this comment, please follow this link

test("given an empty array, it returns an empty array", () => {
const list = [];
const result = dedupe(list);
expect(dedupe(list)).toEqual(result);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What output does this test require for an empty list?

To "like" or "dislike" this comment, please follow this link

Comment thread Sprint-1/implement/max.js
throw new Error("findMax requires an array of numbers");
}

if (!elements.length === 1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For a one-element array, what does !elements.length compare with 1?

To "like" or "dislike" this comment, please follow this link

@cyf-ai-code-reviewer cyf-ai-code-reviewer Bot 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 Nov 25, 2026
@cyf-ai-code-reviewer

Copy link
Copy Markdown

The CYF AI review has left comments. It will only review a PR one time. When you have addressed these comments, please request review again and a volunteer will take a look.

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