Repository navigation
Conversation
… the test.test passed
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Thanks for the PR! You've made good progress and added some solid test coverage, but there are a few correctness and contract issues that need to be addressed before we can merge. Below are the main issues to look into: Sprint-2/implement/lookup.js: Bullet The function currently ignores the input array and hardcodes a fixed mapping instead of dynamically building the lookup from the provided data. Sprint-2/implement/tally.js: Bullet There is a typo in the thrown error string: "tally rquires an input". The task contract expects an error matching "tally requires an array", so the exact message will likely fail tests as-is. |
hey-hammad
left a comment
There was a problem hiding this comment.
Good effort overall, however few areas need attention. Thanks
| @@ -1,5 +1,7 @@ | |||
| // Predict and explain first... | |||
|
|
|||
| // my prediction is that this is not indexed array. it is an array that uses key. | |||
There was a problem hiding this comment.
whats the difference between an array and an object in javascript?
can address be called an array?
There was a problem hiding this comment.
The difference is that array uses index and object uses key to access their values. Address is object
| // Predict and explain first... | ||
|
|
||
| // my prediction here is that we can not use for..of loop because author is not iterable. | ||
| // The reason is, it doesnt use indices it uses keys.instead we will use for..in loop. |
There was a problem hiding this comment.
Its true that author is not iterable.
however the reason for that isn't that it uses keys instead. More on this in the following article.
There was a problem hiding this comment.
Thank you for the article! It is insightful.
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(array) { | ||
| const currency = [ |
There was a problem hiding this comment.
please review the function spec again in lookup.test.js. you're not supposed to hardcode the country codes rather when given them in nested return them in an object.
There was a problem hiding this comment.
I guess I misunderstood what it was asking, took currency as pre-given data and tried to look what the test provided and match. Now I will change the whole approach. Thank you for pointing that out.
There was a problem hiding this comment.
please delete this since you're not working on this optional case.
| @@ -1,15 +1,30 @@ | |||
| function parseQueryString(queryString) { | |||
There was a problem hiding this comment.
what happens when you pass the following input to the fn?
parseQueryString("a+b+c=x+y+z")
is this the correct output?
| expect(invert({})).toEqual({}); | ||
| }); | ||
| //test for one proprty in an object | ||
| test(" should return an empty object if given empty object", () => { |
There was a problem hiding this comment.
test description should match its logic.
| expect(invert({ a: 1 })).toEqual({ 1: "a" }); | ||
| }); | ||
| //test for two property in an object | ||
| test(" should return an empty object if given empty object", () => { |
There was a problem hiding this comment.
test description should match its logic.
| let [key, ...rest] = pair.split("="); | ||
| let value = rest.join("="); | ||
|
|
||
| const lastThreeCharKey = key.slice(-3); |
There was a problem hiding this comment.
is there reason for slicing the last 3 letter word?
are we certain that the key will always contain a 3 character second word?
what if we pass the following input the fn?
parseQueryString("name=John+Doe+Foo&age=30&city=New+York")
is the output correct?
There was a problem hiding this comment.
I have changed it to -2, and why I chose to that because I wanted to differentiate between an equation that hasn't been decoded and a word.
The out put was not correct. Only the first "+" sign was changed. so I made the changes to replace all .
|
|
||
| const lastThreeCharKey = key.slice(-3); | ||
| if (!lastThreeCharKey.includes("+") || key.includes("%")) { | ||
| key = decodeURIComponent(key.replace("+", " ")); |
There was a problem hiding this comment.
using a replace will only replace the first occurrence of "+", what if there are more than one occurrences.
is there another fn that replaces all the occurrences of a char?
|
|
||
| const lastThreeCharKey = key.slice(-2); | ||
| if (!lastThreeCharKey.includes("+") || key.includes("%")) { | ||
| key = decodeURIComponent(key.replaceAll("+", " ")); |
There was a problem hiding this comment.
you're on the right track using replaceAll fn, however there is no need to detect if the key or value contains a "+". Since replaceAll replaces all the instances of "+" we don't need to worry about how many times it appears in the string.
There was a problem hiding this comment.
what I am doing right on that if comparison is that I am checking the last two characters, fore example if the key value has an equation like in one of my tests.(a+b+c=x+y+z) so it will check if the last characters include plus sign and then replace it if it is not equation**( first+name, last+name)**. I am not counting rather I am checking. (There is no other way to change +sign even if I decode it).
before I edited the code I used last three to check for equations with an ending of two characters lets say , 2x + 4x. Can you please explain more about what you want me to do here. I need guidance. Thank you .
Learners, PR Template
Self checklist
Task code
CYF-1083
Changelist
I have done all the course work and created new file for the Invert.js ans have pushed it along with the rest of file
Questions