-
-
Notifications
You must be signed in to change notification settings - Fork 153
LONDON | MAY_2025 | EMILIANO_URUENA | DATA_GROUPS | SPRINT2 #580
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
… MODULE-DATA-GROUPS
…nted with their test, according to instructions. | Sprint-2 MODULE-DATA-GROUPS
…olve it. | Sprint-2 MODULE-DATA-GROUPS
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.
Nice job! A few little things to have a look at. Let me know if anything isn't clear.
@@ -12,4 +12,4 @@ const address = { | |||
postcode: "XYZ 123", | |||
}; | |||
|
|||
console.log(`My house number is ${address[0]}`); | |||
console.log(`My house number is ${address["houseNumber"]}`); |
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 correct, another correct option is address.houseNumber
Sprint-2/debug/author.js
Outdated
for (const value of Object.keys(author)) { | ||
console.log(value); | ||
} | ||
} |
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.
An object is made up of keys and values:
{
<key>: <value>
}
The keys in this example are firstName, lastName, etc.
The values are "Zadie", "Smith", etc.
The comment at the top asks you to log the values. Is that what your code does?
// implementation here | ||
let objectLookup = {} | ||
for (i = 0 ; i< countryCurrencyPairs.length ; i++){ | ||
//const [country, currency] = countryCurrencyPairs[i] | ||
//objectLookup[country] = currency; | ||
objectLookup[countryCurrencyPairs[i][0]] = countryCurrencyPairs[i][1]; | ||
} | ||
return objectLookup |
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 good! Alternatively, there's actually a built in javascript function to do this:
// implementation here | |
let objectLookup = {} | |
for (i = 0 ; i< countryCurrencyPairs.length ; i++){ | |
//const [country, currency] = countryCurrencyPairs[i] | |
//objectLookup[country] = currency; | |
objectLookup[countryCurrencyPairs[i][0]] = countryCurrencyPairs[i][1]; | |
} | |
return objectLookup | |
return Object.fromEntries(countryCurrencyPairs); |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries
Sprint-2/implement/querystring.js
Outdated
const [key, value] = pair.split("="); | ||
queryParams[key] = value; | ||
//const [key, value] = pair.split("=", 2); | ||
const [key, value] = [pair.slice(0,pair.indexOf('=')),pair.slice(pair.indexOf('=')+1)]; |
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 find this line a bit hard to understand. Maybe we could split it up into multiple variables?
const [key, value] = [pair.slice(0,pair.indexOf('=')),pair.slice(pair.indexOf('=')+1)]; | |
const equalsIndex = pair.indexOf('='); | |
const [key, value] = [pair.slice(0,equalsIndex),pair.slice(pair.indexOf('=')+1)]; |
Breakingn it up into multiple lines with clear names makes it easier to follow. You could also break out all the other parts of this.
expect(parseQueryString("sort=newest&color=blue")).toEqual({ | ||
sort: "newest", | ||
color: "blue", | ||
}); | ||
}); |
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.
We could also test for these additional cases:
What happens if the string contains multiple equals signs? e.g. a=b=c=c&b=a
,
What happens if the query string is null, e.g. a
in this example: a=&b=hello
describe('tally',() =>{ | ||
[ | ||
{input:['a'], expected:{ a: 1 }}, | ||
{input:['a', 'a', 'a'], expected:{ a: 3 }}, | ||
{input:['a', 'a', 'b', 'c'], expected:{ a : 2, b: 1, c: 1 }}, | ||
{input:[], expected:{}}, | ||
{input: 'String', expected: new Error("Input must be array")}, | ||
].forEach(({input,expected})=> | ||
it(`return an object containing the count for each unique item for [${input}]`,()=> | ||
expect(tally(input)).toEqual(expected)) | ||
); |
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 testing pattern is great for adding new test cases easily, but the downside is that if a test fails, it can be hard to work out why it has failed, if each test has a clear message, it's more obvious what has gone wrong.
I think either approach is valid though!
[ | ||
{input:{x : 10, y : 20}, expected:{"10": "x", "20": "y"}}, | ||
{input:{ a : 1 }, expected:{ 1 : "a" }}, | ||
{input:{a : 1, b: 2}, expected:{ 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.
what happens if there are multiple identical values? Objects cannot have multiple identical keys.
I'm not sure what should happen in this case.
You could test for it with
{input:{a : 1, b: 2}, expected:{ 1 : "a" , 2 : "b" }}, | |
{input:{a : 1, b: 1}, expected:/* What happens here? */ }, |
modified: Sprint-2/debug/author.js modified: Sprint-2/implement/querystring.js modified: Sprint-2/implement/querystring.test.js modified: Sprint-2/interpret/invert.test.js
Self checklist
Changelist
Sprint 2 - Module DATA GROUPS
COMMITS: