Uh oh!
There was an error while loading. Please reload this page.
Cape Town| 26-ITP-May | Liyema Mfengwana| Sprint 2 | Data Groups - #1444
Cape Town| 26-ITP-May | Liyema Mfengwana| Sprint 2 | Data Groups#1444LiyemaMfengwana wants to merge 18 commits into
Conversation
| if (Array.isArray(object)) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Could you make this function to also return false when the first parameter is not an object? For examples, null, undefined, 1234, "ABCD".
| // Given invalid parameters like an array | ||
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| test("returns false for invalid input types", () => { | ||
| expect(contains([1, 2, 3], "propertyName")).toBe(false); | ||
| }); |
There was a problem hiding this comment.
This test could not yet confirm that the function correctly returns false when the first argument is an array.
This is because contains([1, 2, 3], "propertyName") could also return false simply because "propertyName" is not a key of the array.
The indices of an array acts as the keys of the array. A proper test should use a valid
key to ensure the function returns false specifically because the input is an array, not because the key is missing.
| const counts = {}; | ||
| for (const item of items) { | ||
| counts[item] = (counts[item] || 0) + 1; | ||
| } |
There was a problem hiding this comment.
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, or
- use
Object.hasOwn()
Self checklist
Changelist
Complete work