Sheffield | 26-Jan-ITP | Martha Ogunbiyi| Sprint 2| Coursework/sprint 2#1133
Sheffield | 26-Jan-ITP | Martha Ogunbiyi| Sprint 2| Coursework/sprint 2#1133marthak1 wants to merge 9 commits intoCodeYourFuture:mainfrom
Conversation
| for (const value in author) { | ||
| console.log(value); | ||
| } |
There was a problem hiding this comment.
Does this code output the property values such as "Zadie", "Smith", ...?
There was a problem hiding this comment.
Thanks for the feedback, i have update to output the values rather the keys
| if (obj.constructor !== Object) { | ||
| throw new Error("Invalid Parameter"); | ||
| } | ||
| return Object.keys(obj).includes(targetKey); |
There was a problem hiding this comment.
Can also use Object.hasOwn() -- probably a more efficient approach.
| // Given invalid parameters like an array | ||
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| test("given an invalid parameters, it should return false or throw an error", () => { | ||
| const input = ['a', 'b', 'c']; | ||
| const target = 'a' | ||
| expect(() => contains(input, target)).toThrow(); | ||
|
|
||
| }); |
There was a problem hiding this comment.
This test does not yet confirm that the function correctly returns false when the first argument is an array.
This is because contains(['a', 'b', 'c'], "a") could also return false simply because "a" is not a key of the array.
Arrays are objects, with their indices acting as keys. A proper test should use an array along with a valid key to ensure the function returns false specifically because the input is an array, not because the key is missing.
| if (obj.constructor !== Object) { | ||
| throw new Error("Invalid Parameter"); | ||
| } |
There was a problem hiding this comment.
For each of the following function calls, does your function return the value you expect?
const obj = new Map(); // Map object is an object
obj.foo = 1;
contains(obj, "foo");
// According to the spec in the test file, the function should also reject
// array (even though array is a kind of objects in JS)
contains([0, 0, 0], "1");
contains(null, "1");
contains(undefined, "1");
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| const index = pair.indexOf("="); | ||
|
|
||
| if (index === -1) { | ||
| queryParams[pair] = ""; | ||
| continue; | ||
| } | ||
| const key = pair.slice(0, index); | ||
| const value = pair.slice(index + 1); | ||
| queryParams[key] = value; | ||
| } |
There was a problem hiding this comment.
For the following function call, does your function return the value you expect?
parseQueryString("key1=value1&&key2=value2")
| function tally() {} | ||
| function tally(list) { | ||
| const uniqueItems = {}; | ||
| if(list.constructor === String){ |
There was a problem hiding this comment.
Why only treat string as invalid argument? What about other data types: null, undefined, 123, true, etc.
| for (const frequency of list){ | ||
| uniqueItems[frequency] = (uniqueItems[frequency] || 0) + 1; | ||
| } |
There was a problem hiding this comment.
Indentation is off.
Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode,
as recommended in https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md ?
| @@ -1,3 +1,14 @@ | |||
| function tally() {} | |||
| function tally(list) { | |||
| const uniqueItems = {}; | |||
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.
Learners, PR Template
Self checklist
Changelist
Sprint 2 coursework done