London |ITP-Jan-2016 | Ping Wang | Sprint 2 |Coursework#1023
London |ITP-Jan-2016 | Ping Wang | Sprint 2 |Coursework#1023pathywang wants to merge 7 commits intoCodeYourFuture:mainfrom
Conversation
| for (const ingredient of recipe.ingredients) { | ||
| console.log(ingredient); | ||
| } |
There was a problem hiding this comment.
This work.
Alternate approach to explore:
Since ingredient values are separated by '\n' in the output, we could also use Array.prototype.join() to construct the equivalent string and then output the resulting string.
| object={name:'jin', age:13} | ||
| console.log (contains(object, 'nice')) | ||
| test.todo("contains no nice property in object return false") | ||
|
|
||
|
|
||
|
|
||
| // Given invalid parameters like an array | ||
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| object={name:'jin', age:13} | ||
| console.log (contains(object, '[1,2,5]')) | ||
| test.todo("contains no array property in object return false") |
There was a problem hiding this comment.
test.todo(" ... ") is just a placeholder to serve as a reminder for "what needs to be done". You were supposed to implement the corresponding Jest tests described in the comments on this file.
Can you implement all the tests in all the .test.js files?
| function createLookup(countryCurrencyPairs) { | ||
| const countryCodeCurrency={} | ||
| for (const[country, currency] of countryCurrencyPairs){ | ||
| countryCodeCurrency[country]=currency | ||
| } | ||
|
|
||
| return countryCodeCurrency | ||
| } |
There was a problem hiding this comment.
The spacing around the operators is not quite consistent.
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
?
| const result1=createLookup([['GB','GBP']]) | ||
| console.log(result1) | ||
| test.todo('creates a single county code currency ') | ||
|
|
||
| //given an empty country currency pair/array | ||
| console.log(createLookup([[]])) | ||
| test.todo('return an empty object with empty pair given') No newline at end of file |
There was a problem hiding this comment.
-
Should also implement these tests
-
Better practice to end each statement by a semicolon (
;) to reduce chance of errors.
| console.log(parseQueryString("color=blue&quality=good")) | ||
| console.log(parseQueryString("equation=x=y+1")) | ||
| console.log(parseQueryString("")) |
There was a problem hiding this comment.
For each of the following function calls, does your function return the value you expect?
parseQueryString("a=b&=&c=d")
parseQueryString("a=b&&c=d")
Note:
-
(Implementing this is optional) 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.
| if (!Array.isArray(array)) { | ||
| throw new Error("Invalid input: expected an array"); | ||
| } | ||
|
|
||
| const count={} | ||
| for(item of array){ | ||
| if (count[item]){ | ||
| count[item] += 1 | ||
| } | ||
| else{ | ||
| count[item] = 1 | ||
| } | ||
| } | ||
| return count | ||
| } |
There was a problem hiding this comment.
-
Can you improve the indentation?
-
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.
Self checklist
Changelist
i did coursework with node or npm jest to check my work to make sure that my code works as expected after i completed my prep