Skip to content

ZA Cape Town | ITP-May-2025 | Dawud Vermeulen | Sprint 2 | Module-Data-Groups #755

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 4 commits into
base: main
Choose a base branch
from

Conversation

Dave-Vermeulen
Copy link

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 | FirstName LastName | Sprint | Assignment Title
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

completed the tasks within:

  • Debug
  • Implement
  • Interpret

Questions

Please review my PR 🙏🏽

@Dave-Vermeulen Dave-Vermeulen added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 9, 2025
@cjyuan cjyuan added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Aug 9, 2025
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

  • You missed updating the .test.js files

Comment on lines 3 to 10
if(obj === null || obj === undefined){
return false
}
return obj[property] !== undefined;
}

module.exports = contains;
// work done.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you expect the from the following function calls?

contains("ABC", "1");
contains(["A", "B", "C"], "1");
contains(123, "1");
contains(true, "1");
contains({ key: undefined }, "key");

Suggestion:, Look up JS "in" operator vs Object.hasOwn.

Copy link
Author

Choose a reason for hiding this comment

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

okay ended up going with Object.hasOwn

Comment on lines 11 to 13
const key = parts[0];
const value = parts.length > 1 ? parts.slice(1).join('=') : ''; //clunky but it works to split them and stitch it together again
queryParams[key] = value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that in real querystring, both key and value are percent-encoded or URL encoded in the URL. For example, the string "5%" will be encoded as "5%25". So to get the actual value of "5%25" (whether it is a key or value in the querystring), you should call a function to decode it.
May I suggest looking up any of these terms, and "How to decode URL encoded string in JS"?

Copy link
Author

@Dave-Vermeulen Dave-Vermeulen Aug 17, 2025

Choose a reason for hiding this comment

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

thanks for the guidance

Copy link
Author

Choose a reason for hiding this comment

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

this took some research. thank you for making the problem real so i can relate to it better. it made me invest more in the answer

Comment on lines 1 to 11
function tally(items) {
if (!Array.isArray(items)){
throw new TypeError('that aint no array bay bay'); //okay so this is the biggie smalls and its working
}
const counts = {};

for (const item of items){
counts[item] = (counts[item] || 0) +1; //simple sexy core logic
}
return counts;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the following function call returns the value you expect?

tally(["toString", "toString"]);

Suggestion: Look up an approach to create an empty object with no inherited properties.

@@ -10,20 +10,30 @@ function invert(obj) {
const invertedObj = {};

for (const [key, value] of Object.entries(obj)) {
invertedObj.key = value;
const numKey = Number(key);
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't have to convert the key to a number when it looks like a number.

Comment on lines 29 to 31
// {'1':'a'}
// b) What is the current return value when invert is called with { a: 1, b: 2 }
// { '1': 'a', '2': 'b'}
Copy link
Contributor

Choose a reason for hiding this comment

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

These are the expected return value from the original code, not the actual return value.

Copy link
Author

Choose a reason for hiding this comment

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

okay i have edited my answer

Comment on lines 36 to +37
// d) Explain why the current return value is different from the target output

// cause its converted to strings, the key must be a int and the value must be a string.
Copy link
Contributor

Choose a reason for hiding this comment

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

The question is asking, why with the original code, invert({a: 1}) does not return {'1': a} (or {1:a}).

Note: The property name (key) is always a string. Even when we express the key as a number (e.g., { 1 : 'a' }), the key will still be converted to a string '1'.

Copy link
Author

Choose a reason for hiding this comment

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

Okay i refactored the code a bit so that it makes sense. I understand the comments you made but it was difficult to circle back to this and I could not take into consideration the comment in isolation.

@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. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Aug 9, 2025
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Have you also gone through my comments on Sprint-2/interpret/invert.js in the previous review?

Comment on lines 29 to 35
it('should handle non-object inputs gracefully', () => {
expect(contains(123, 'a')).toBe(false); // Number
expect(contains("hello", 'a')).toBe(false); // String
expect(contains([1, 2, 3], 'a')).toBe(false); // Array
expect(contains(true, 'a')).toBe(false)
expect(contains(NaN, 'a')).toBe(false)
});
Copy link
Contributor

Choose a reason for hiding this comment

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

contains([1, 2, 3], "a") could also return false because "a" is not a property (or key) of [1, 2, 3].
However, "0", "1", "2" are keys of [1, 2, 3], so it is better to specify the test as
expect(contains([1, 2, 3], "1")).toBe(false); (to ensure you are checking what you describe)

You would also need to check if the first parameter is an array in your function.

Copy link
Author

Choose a reason for hiding this comment

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

okay i added this test but then felt needed to update the function to handle it.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Aug 18, 2025
@cjyuan
Copy link
Contributor

cjyuan commented Aug 18, 2025

Changes look good. Well done.

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

Successfully merging this pull request may close these issues.

2 participants