Skip to content

West Midlands | 26-Jan-ITP | Fida Ali Zada | Sprint 1 | Data Groups#982

Closed
alizada-dev wants to merge 12 commits intoCodeYourFuture:mainfrom
alizada-dev:coursework/sprint-1
Closed

West Midlands | 26-Jan-ITP | Fida Ali Zada | Sprint 1 | Data Groups#982
alizada-dev wants to merge 12 commits intoCodeYourFuture:mainfrom
alizada-dev:coursework/sprint-1

Conversation

@alizada-dev
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

Changelist

Completed all the exercises of sprint 1 from the Data Group module.

@alizada-dev alizada-dev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 7, 2026
Comment thread Sprint-1/fix/median.js Outdated
Comment thread Sprint-1/fix/median.js Outdated
Comment thread Sprint-1/fix/median.js Outdated
Comment thread Sprint-1/fix/median.js Outdated
Comment thread Sprint-1/implement/dedupe.js Outdated
Comment on lines 24 to +31
// Given an array with no duplicates
// When passed to the dedupe function
// Then it should return a copy of the original array

test("if no duplicates, return the copy of the original array", () => {
expect(dedupe([1, 3, 5, 7])).toEqual([1, 3, 5, 7]);
})

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 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?

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.

By implementing return [...new Set(array)];, the test will pass correctly, because this implementation always returns a new 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.

The concern here is not about your function implementation -- it was correct.

The issue is, how to prepare a test to check if the function is indeed returning a copy of the original array.

With the test you had, a function like this could also pass the test.

function  dedupe(array) {
  const set = new Set(array);
  if (set.size == array.length) return array;
  return [...set];
}  

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.

const input = [1, 3, 5, 7];
const result = dedupe(input);

expect(result).toEqual(input);
expect(result).not.toBe(input);

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.

With this test, there is a chance that, even though result has incorrect elements (for example, []),
the two tests could still pass. Can you figure out why, and then fix the tests accordingly?

Copy link
Copy Markdown
Author

@alizada-dev alizada-dev Mar 24, 2026

Choose a reason for hiding this comment

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

const input = [1, 3, 5, 7];
const result = dedupe(input);

expect(result).toEqual([1, 3, 5, 7]);
expect(result).not.toBe([1, 3, 5, 7]);

Is it alright, this time?

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 not correct. Try looking up the difference between toBe() and toEqual().

Comment thread Sprint-1/implement/max.js Outdated
Comment thread Sprint-1/implement/max.test.js
Comment thread Sprint-1/implement/sum.test.js
Comment thread Sprint-1/stretch/aoc-2018-day1/solution.js
@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
@alizada-dev alizada-dev 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 24, 2026
@cjyuan
Copy link
Copy Markdown
Contributor

cjyuan commented Mar 24, 2026

The proposed test in dedupe.test.js is not quite correct.

All other changes look good.

@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 24, 2026
@illicitonion
Copy link
Copy Markdown
Member

Closing PR because the January ITP run has finished. Feel free to re-open if you're still working on it.

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.

3 participants