-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
base: main
Are you sure you want to change the base?
ZA Cape Town | ITP-May-2025 | Dawud Vermeulen | Sprint 2 | Module-Data-Groups #755
Conversation
There was a problem hiding this 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
Sprint-2/implement/contains.js
Outdated
if(obj === null || obj === undefined){ | ||
return false | ||
} | ||
return obj[property] !== undefined; | ||
} | ||
|
||
module.exports = contains; | ||
// work done. |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
Sprint-2/implement/querystring.js
Outdated
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; |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the guidance
There was a problem hiding this comment.
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
Sprint-2/implement/tally.js
Outdated
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; | ||
} |
There was a problem hiding this comment.
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.
Sprint-2/interpret/invert.js
Outdated
@@ -10,20 +10,30 @@ function invert(obj) { | |||
const invertedObj = {}; | |||
|
|||
for (const [key, value] of Object.entries(obj)) { | |||
invertedObj.key = value; | |||
const numKey = Number(key); |
There was a problem hiding this comment.
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.
Sprint-2/interpret/invert.js
Outdated
// {'1':'a'} | ||
// b) What is the current return value when invert is called with { a: 1, b: 2 } | ||
// { '1': 'a', '2': 'b'} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
// 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. |
There was a problem hiding this comment.
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'
.
There was a problem hiding this comment.
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.
There was a problem hiding this 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?
Sprint-2/implement/contains.test.js
Outdated
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) | ||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Changes look good. Well done. |
Learners, PR Template
Self checklist
Changelist
completed the tasks within:
Questions
Please review my PR 🙏🏽