London | ITP-JAN-2026 | Said Fayaz Sadat | Sprint 2 | coursework/sprint 2#1083
London | ITP-JAN-2026 | Said Fayaz Sadat | Sprint 2 | coursework/sprint 2#1083fayaz551 wants to merge 9 commits intoCodeYourFuture:mainfrom
Conversation
…ing their property names by (dot). instead of index
…ts it as ordered list in for of so we can use for in in objects to access its key and value pair
…ray and then used line break to make each of them in new line
| for (const value in author) { | ||
| console.log(value); | ||
| } |
There was a problem hiding this comment.
Does this output "Zadie", "Smith", ... (the value of the properties)?
| function contains() {} | ||
|
|
||
| function contains(obj, key) { | ||
| return key in obj; |
There was a problem hiding this comment.
Consider the following two approaches for determining if an object contains a property:
let obj = {}, propertyName = "toString";
console.log( propertyName in obj ); // true
console.log( Object.hasOwn(obj, propertyName) ); // false
Which of these approaches suits your needs better?
For more info, you can look up JS "in" operator vs Object.hasOwn.
In addition, the function is expected to return false when the first parameter is an array or is not an object.
| // Given invalid parameters like an array | ||
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| test("contains on invalid parameters returns false", () => { | ||
| expect(contains([], "a")).toBe(false); | ||
| }); |
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") 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 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.
| function createLookup(countryCurrencyPairs) { | ||
| let lookup ={}; | ||
| for(let pair of countryCurrencyPairs){ | ||
| let key = pair[0]; | ||
| let value = pair[1]; | ||
| lookup[key] = value; | ||
| } | ||
| return lookup; | ||
|
|
||
|
|
||
|
|
||
| } |
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
?
| value = pair.slice(index + 1); | ||
| } | ||
|
|
||
| queryParams[key] = value; |
There was a problem hiding this comment.
Note: (No change required)
-
In real query string, both
keyandvalueare percent-encoded or URL encoded in the URL.
For example, the string "5%" is encoded as "5%25". So to get the actual value of "5%25"
(whether it is a key or value in the query string), we need to call a function to decode it. -
You can also explore the
URLSearchParamsAPI.
| const result = {}; | ||
|
|
||
| for (const item of items) { | ||
| if (result[item]) { | ||
| result[item]++; | ||
| } else { | ||
| result[item] = 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.
Learners, PR Template
Self checklist
Changelist
Debugged and Implementation done for multiple tasks with jest cases for some.
Questions
n/a