London | 26-ITP-May | Damilola Odumosu | Sprint 2 | Coursework - #1352
London | 26-ITP-May | Damilola Odumosu | Sprint 2 | Coursework#1352d-odumosu wants to merge 9 commits into
Conversation
| console.log(value); | ||
| //An object is not directly iterable, if we want to log out the values we can use a for in loop | ||
| for (const value in author) { | ||
| console.log(`${author[value]}`); |
There was a problem hiding this comment.
Why not just call the function asconsole.log(author[value]) ?
| ingredients: | ||
| ${recipe}`); | ||
| ingredients:`); | ||
| for (const value of Object.values(recipe.ingredients)) { |
There was a problem hiding this comment.
Why not use the for-of loop to iterate through the array recipe.ingredients directly? That is, without Object.values().
| if (Array.isArray(object)) { | ||
| throw new Error("Expected an object, received an array"); | ||
| } |
There was a problem hiding this comment.
What if object is null, undefined, 1234, true, or "1234"?
| const obj = Object.keys(object); | ||
| if (obj.length === 0) { | ||
| return false; | ||
| } | ||
| return obj.includes(property); |
There was a problem hiding this comment.
This works. Could also explore Object.hasOwn()
| const arr = []; | ||
| const propertyNameCheck4 = "name"; |
There was a problem hiding this comment.
Arrays are objects, with their indices acting as keys. A proper test should use a non-empty 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.
| test("should ignore empty key-value pairs", () => { | ||
| expect(parseQueryString("key1=value1&&key2=value2&")).toEqual({ | ||
| key1: "value1", | ||
| key2: "value2", | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Could your function pass this test?
| queryParams[key] = value; | ||
| const indexOfFirst = pair.indexOf("="); | ||
| if (indexOfFirst === -1) { | ||
| queryParams[pair] = ""; |
There was a problem hiding this comment.
Note: The value of pair has not yet been decoded.
| return arr.reduce((acc, cur) => { | ||
| acc[cur] = (acc[cur] || 0) + 1; | ||
| return acc; | ||
| }, {}); |
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