-
-
Notifications
You must be signed in to change notification settings - Fork 193
West Midlands | ITP-Sept-25 | Georgina Rogers | Sprint 2 | Coursework Sprint 2 #862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Sprint-2/implement/tally.js
Outdated
| if (!Array.isArray(items)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
| const counts = {}; // empty object to store tally of key-value pairs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is my output: [Object: null prototype] { toString: 2 }
is this correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This is because the object no longer has an inherited toString() method.
The purpose of using Object.create(null) is so that, when the created object is used as a lookup table, it can accept any string as its property.
An alternative approach is to use a Map object as a lookup table.
|
|
||
| // 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "current return value" in questions (a), (b), and (d) refers to the value returned by the original (unmodified) function.
The objects you described on line 28 and 31 are not the objects returned by the original function.
The explanation given on line 41 (answer to question (d)) is also not quite correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have rewritten my answer for (d) , I am struggling to understand if you mean my answers to (a) and (b) are incorrect, or if it was just the explanation that was incorrect?
Learners, PR Template
Self checklist
Changelist
Bugs predicted, tested and fixed.
Implement functions based off a set of requirements.
Interpret a program.
Questions
.