London | 26-ITP-January | Mouawia Elkhalifa | Sprint 2 | Data Groups#1077
London | 26-ITP-January | Mouawia Elkhalifa | Sprint 2 | Data Groups#1077MouawiaElkhalifa wants to merge 4 commits intoCodeYourFuture:mainfrom
Conversation
Sprint-2/implement/contains.test.js
Outdated
| test("return false when paramters invaliud ", () =>{ | ||
| expect(contains([], "a")).toEqual(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.
There was a problem hiding this comment.
Strengthened the array test to return false even if an index exists (e.g., contains(["a"], 0)).
|
|
||
| // d) Explain why the current return value is different from the target output | ||
|
|
||
| // e) Fix the implementation of invert (and write tests to prove it's fixed!) |
There was a problem hiding this comment.
You deleted your answers to these questions.
Anyway, do you recognise what this statement (in the original code) does?
invertedObj.key = value;
There was a problem hiding this comment.
Restored missing answers (a-e) and corrected the logic. Replaced literal .key with dynamic [value] notation to prevent overwriting and ensure keys are swapped correctly.
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good. Well done.
Sprint-2/interpret/invert.js
Outdated
| // a) What is the current return value when invert is called with { a : 1 } | ||
| // {"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.
I think the "current return value" refers to the return value of the original code.
The value you showed is the "target return value".
I am sure you know the answers.
There was a problem hiding this comment.
thanks,Fixed (a) and (b) — they now show the correct current output.
Learners, PR Template
Self checklist
Changelist
Implemented all Sprint 2 exercises including:
All functions were tested and verified to meet the expected behavior. Edge cases such as invalid input and duplicate values were handled where required.