London | 26-ITP-May | Edina Kurdi | Sprint 2 | Coursework - #1422
London | 26-ITP-May | Edina Kurdi | Sprint 2 | Coursework#1422edinakurdi wants to merge 15 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
4 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| console.log(Object.values(author)); | ||
| // for (const value of author) { | ||
| // console.log(value); | ||
| // } |
There was a problem hiding this comment.
A good workaround to print the values of the object.
Question - how could the for loop on lines 21 - 23 be changed (to a different loop for example) to achieve the same effect?
There was a problem hiding this comment.
Created an alternative using a loop
| const recipeValues = Object.values(recipe); | ||
| // ["bruschetta", 2, ["olive oil", "tomatoes", "salt", "pepper"]] | ||
|
|
||
| const ingredients = recipeValues.slice(-1)[0]; | ||
| // ["olive oil","tomatoes","salt","pepper"] | ||
|
|
There was a problem hiding this comment.
good use of methods but how could we reduce the amount of code we're writing here?
Is there a more direct way to access the ingredients so you can join them on line 25?
There was a problem hiding this comment.
oh, i seem to have created more work for myself than needed. corrected now
| if (keysInObject.includes(propertyName)) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
How could you refactor these lines to be more concise?
There was a problem hiding this comment.
yes, since it returns a boolean, I dont have to write if else statement. done.
| describe("when given valid inputs", () => { | ||
| test("should return an object where (Input ==> Output): keys:values ==> country code: corresponding currency", () => { | ||
| expect( | ||
| createLookup([ | ||
| ["US", "USD"], | ||
| ["CA", "CAD"], | ||
| ]) | ||
| ).toEqual({ | ||
| US: "USD", | ||
| CA: "CAD", | ||
| }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Could you have included a simpler test to start with for valid inputs?
There was a problem hiding this comment.
i added a simpler input with only one array in the array (one country's data)
| test.todo("contains on empty object returns false"); | ||
| describe("given an empty object", () => { | ||
| test("should return false when passed to contains", () => { | ||
| expect(contains({}, "a").toBe(false)); |
There was a problem hiding this comment.
This line fails - please correct it
There was a problem hiding this comment.
oh those brackets... fixed now.
| throw new Error("Invalid input. All elements should be arrays"); | ||
| } | ||
|
|
||
| return Object.fromEntries(countryCurrencyPairs); |
There was a problem hiding this comment.
thank you i came across it when learning about iterating through objects. very handy.
| //each key-value pair will form an array in a bigger array (array of arrays of key-value pairs) | ||
|
|
||
| // d) Explain why the current return value is different from the target output | ||
| /* issues: | ||
| - .key notation naming the key "key" | ||
| - we only assign the key to value, but not reversing it | ||
| */ |
| expect(tally(["a"])).toEqual({ a: 1 }); | ||
| expect(tally(["a", "a", "a"])).toEqual({ a: 3 }); | ||
| expect(tally(["a", "a", "b", "c"])).toEqual({ a: 2, b: 1, c: 1 }); |
There was a problem hiding this comment.
I actually think these are three different behaviours and so deserve their own test blocks to anyone reading them test suite can see the different behaviours clearly.
| @@ -1,3 +1,18 @@ | |||
| function tally() {} | |||
| function tally(array) { | |||
| if (typeof array === "string") { | |||
There was a problem hiding this comment.
What if the input is a number or a boolean? How can you change this condition so it will hold up against any wrong input type?
There was a problem hiding this comment.
yes, i took the instructions too literally :)
corrected and test written for this version
| throw new Error("Input should be an array"); | ||
| } | ||
|
|
||
| let tallySet = {}; |
There was a problem hiding this comment.
Would this code still work if you made the variable a constant? Explain your answer :)
There was a problem hiding this comment.
yes, and updated it.
It would work still, as the variable ramains the same, we are not trying to update it, merely working with the items inside
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| //filter out empty strings from the keyValuePairs array of strings | ||
| let filteredKeyValuePairs = keyValuePairs.filter( |
There was a problem hiding this comment.
yes, and i changed it now. (as above) I need to rememer to use const instead of let
Poonam-raj
left a comment
There was a problem hiding this comment.
Few comments, slight amendments/refactors or explanations needed - take a look, nice work here though, good use of methods and testing throughout
Learners, PR Template
Self checklist
Changelist
Data Groups - Sprint 2