Skip to content

ZA-ITP-May-2025 | Christian Mayamba | Module-Data-Groups | Week 1 #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

c-mayamba
Copy link

@c-mayamba c-mayamba commented Jul 10, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Briefly explain your PR.

Questions

Ask any questions you have for your reviewer.

@c-mayamba c-mayamba added the Needs Review Participant to add when requesting review label Jul 10, 2025
Copy link

Choose a reason for hiding this comment

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

Tests passed, well done

Copy link

Choose a reason for hiding this comment

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

Tests passed, well done

Copy link

Choose a reason for hiding this comment

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

Tests passed, well done

Copy link

Choose a reason for hiding this comment

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

Tests passed, well done

Copy link

Choose a reason for hiding this comment

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

code looks fine

@fearcyf
Copy link

fearcyf commented Jul 11, 2025

Well done, Do some further research on the test.each approach in making code more concise. Also use const when variable does not need reassignment.

@fearcyf fearcyf self-assigned this Jul 11, 2025
@fearcyf fearcyf added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jul 11, 2025
Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

There are some significant things for you to look at around making sure you're solving the most general version of a problem, not just passing the tests which happen to be included. Please give this some thought and try those exercises again, working with volunteers if you need help!

Comment on lines +17 to +23
if (
list.every(
(item) => typeof item === "string" || item === null || item === undefined
)
) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

This code looks like it wouldn't handle extra test-cases we could write, e.g. what would happen if the list contained only boolean values (true/false)?

We want to write code which is general - that is, it fixes the core problem statement, rather than a particular set of tests - please try to rewrite this so that it's more general.

}

if (numbersArray.length % 2 === 0) {
const tempMedian =
Copy link
Member

Choose a reason for hiding this comment

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

tempMedian isn't a very clear name for this variable - can you think of a more clear name?

Comment on lines +28 to +29
const median1 = tempMedian / 2;
return median1;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you're calling this median1 rather than just median?

(And in fact, maybe you don't need a variable at all here - what value do you think the variable provides over just writing return tempMedian / 2;?)

return median1;
} else {
const middleIndex = Math.floor(numbersArray.length / 2);
const median = numbersArray.splice(middleIndex, 1)[0];
Copy link
Member

Choose a reason for hiding this comment

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

This branch uses splice whereas the other branch doesn't - why are you getting elements differently in the two branches? What does splice do which is maybe useful or unhelpful?

Comment on lines +2 to +11
if (array.length === 0) {
return [];
}

const duplicates = array.filter(
(item, index) => array.indexOf(item) !== index
);

const set2 = new Set(duplicates);
return array.filter((item) => !set2.has(item));
Copy link
Member

Choose a reason for hiding this comment

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

This feels like quite a complicated way of deduplicating an array. I'm also not quite sure it's behaving as the comments in the test file suggest. Can you give this another try? First focus on making sure you understand the requirements, then see if you can make it simpler.

Comment on lines 32 to +34
// Then it should remove the duplicate values, preserving the first occurence of each element
test("array with strings and numbers, it should remove duplicates", () => {
expect(dedupe([10, "hi", "hey", 20, "hey", 30])).toEqual([10, "hi", 20, 30]);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this test does the same as the comment describes. The comment says "preserves the first occurence", but your test doesn't keep the first "hey".

return "-Infinity";
}

if (elements.every((item) => typeof item === "string")) {
Copy link
Member

Choose a reason for hiding this comment

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

Same question as before - is "I can't find the max of an array of only strings" really the general statement here?

}

if (elements.every((item) => typeof item === "string")) {
return "undefined";
Copy link
Member

Choose a reason for hiding this comment

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

Returning the string "undefined" seems like an odd choice here. Can you think of a more appropriate value to return?

return 0;
}

if (elements.every((item) => typeof item === "string")) {
Copy link
Member

Choose a reason for hiding this comment

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

Same questions as above

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants