Sheffield | 25-ITP-Sep | Xiayidan Abuxuukuer | Sprint 2 | Coursework#874
Sheffield | 25-ITP-Sep | Xiayidan Abuxuukuer | Sprint 2 | Coursework#874Shayida999 wants to merge 1 commit intoCodeYourFuture:mainfrom
Conversation
|
Your PR description contained template fields which weren't filled in. Check you've ticked everything in the self checklist, and that any sections which prompt you to fill in an answer are either filled in or removed. If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
| }; | ||
|
|
||
| for (const value of author) { | ||
| for (const value of of Object.values(author)) { |
There was a problem hiding this comment.
This works, however please note there are more cleaner ways to achieve this. Knowing those will definitely help in the future.
| @@ -1,3 +1,20 @@ | |||
| function contains() {} | |||
| function contains(obj, prop) { | |||
There was a problem hiding this comment.
This fulfils the requirements, now think of the below:
- What will happen if we inverse the
if conditioncheck. - What does
hasOwnPropertymethod return, do we need explicit return statement
This will help make this more better and less cluttered!
| for (let i = 0; i < pairs.length; i++){ | ||
|
|
||
| const country = pairs[i][0]; | ||
| const country = pairs[i][1]; |
There was a problem hiding this comment.
Maybe a typo here, country is a constant, can it be redeclared?
|
|
||
| const country = pairs[i][0]; | ||
| const country = pairs[i][1]; | ||
| lookup[country] = currency; |
There was a problem hiding this comment.
Does currency exist in the global and local scope?
|
|
||
| for (let i = 0; i < pairs.length; i++){ | ||
|
|
||
| const country = pairs[i][0]; |
There was a problem hiding this comment.
There is cleaner way de-structuring of accessing the values, if we expect the array to have fixed number of items,
| for (let i = 0; i < keyValuePairs.length; i++){ | ||
| const pair = keyValuePairs[i]; | ||
| const indexOfEquals = pair.indexOf("="); | ||
| if(indexOfEquals === -1){ |
| function tally() {} | ||
| function tally(array) { | ||
|
|
||
| if (!Array.isArray(arr)) { |
| if (counts[item]) { | ||
|
|
||
| counts[item]= counts[item] + 1; | ||
| } | ||
| else { | ||
| counts[item]= 1; | ||
| } |
There was a problem hiding this comment.
What if we start at 0 when the key is undefined and then increment by 1 if exists. Will shorten the code for sure.
| // c) What does Object.entries return? Why is it needed in this program? | ||
| [["a", 1], ["b", 2]] | ||
|
|
||
| // d) Explain why the current return value is different from the target output |
There was a problem hiding this comment.
This is asking why does the current invert function returns {key: 2} when { a: 1, b: 2 } is passed as argument. Shouldn't the function return {"1": "a", "2": "b"}?
| const invertedObj = {}; | ||
|
|
||
| for (const [key, value] of Object.entries(obj)) { | ||
| invertedObj.key = value; |
There was a problem hiding this comment.
This will create key key in the object invertedObj, is that our goal (make key to value and value to key).
Learners, PR Template
Self checklist
Changelist
Questions
none for now. Thanks.