Skip to content

London | 26-ITP-Sep | Mahir Shah | Sprint 1 | Data Groups - #1481

Open
MahirShah300 wants to merge 14 commits into
CodeYourFuture:mainfrom
MahirShah300:Sprint-1
Open

MahirShah300 wants to merge 14 commits into
CodeYourFuture:mainfrom
MahirShah300:Sprint-1

Conversation

@MahirShah300

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

Implemented tests and functions.

@MahirShah300 MahirShah300 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 30, 2026
@cjyuan cjyuan added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 4, 2026
Comment thread Sprint-1/fix/median.js
Comment on lines +17 to +20
!list.every(
(currentValue) =>
typeof currentValue === "number" && !Number.isNaN(currentValue)
)

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 also consider excluding +/- Infinity.

  • Could probably give a simpler name than currentValue to the parameter. The prefix "current" does not add any new info.

Comment on lines +4 to +8
for (value of elements) {
if (!dedupedArray.includes(value)) {
dedupedArray.push(value);
}
}

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 loop variable value be declared using const or let in this loop?

Comment on lines -21 to +22
// Given an array with no duplicates
// When passed to the dedupe function
// Then it should return a copy of the original array
test("given an array with no duplicates, should return a copy of the same array", () => {
expect(dedupe([1, 5, 9, 23])).toEqual([1, 5, 9, 23]);
});

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 specified in the original comment:

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 on lines +27 to +34
if (list.length === 0) {
return "Could not calculate a median: calculateMedian requires a non-empty array";
}

if (!Array.isArray(list)) {
return "Could not calculate a median: calculateMedian requires an array of numbers";
}
}

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 you look up how to use a try...catch block to catch a thrown error object, then simplify the code on lines 27-33 into a single line by constructing the return value from the error object's message property?

Comment thread Sprint-1/implement/max.js
Comment on lines +19 to +21
sortedElements = elements.toSorted((a, b) => a - b);

return sortedElements[sortedElements.length - 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.

This work.

Suggestion: Explore a more efficient approach to find the largest numbers in an array.

Comment on lines +11 to +14
!list.every(
(currentValue) =>
typeof currentValue === "number" && !Number.isNaN(currentValue)
)

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.

  • Infinity is also a value of type "number".

  • Could also consider importing sum() from sum.js and use it in this script.

Comment on lines +25 to +27
test("given an array with decimal numbers, correctly return total sum", () => {
expect(sum([12.7, 3.6, 32.48, 8, 32.53])).toEqual(89.31);
});

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.

console.log(12.7 + 3.6 + 32.48 + 8 + 32.53   == 89.31);  // true

// When numbers are added in different order
console.log(32.53 + 8 + 32.48 + 3.6 + 12.7   == 89.31);  // 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

function includes(list, target) {
for (let index = 0; index < list.length; index++) {
const element = list[index];
for (element of list) {

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.

Loop variable element has never been declared.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Nov 4, 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