Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Emilianouz
Copy link

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

Sprint 2 - Module DATA GROUPS
COMMITS:

  1. Debugs: address.js, author.js, recipe.js, were debuged. | Sprint-2 MODULE-DATA-GROUPS
  2. Implemented: contains, lookup, querystring, and tally were implemented with their test, according to instructions. | Sprint-2 MODULE-DATA-GROUPS
  3. Interpret: Questions answered in invert.js, created the test and solve it. | Sprint-2 MODULE-DATA-GROUPS

…nted with their test, according to instructions. | Sprint-2 MODULE-DATA-GROUPS
@Emilianouz Emilianouz added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Participant to add when requesting review labels Jul 11, 2025
Copy link

@MorganDavid MorganDavid left a 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"]}`);

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

Comment on lines 14 to 16
for (const value of Object.keys(author)) {
console.log(value);
}
}

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?

Comment on lines 2 to +9
// 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

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:

Suggested change
// 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

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)];
Copy link

@MorganDavid MorganDavid Jul 12, 2025

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?

Suggested change
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.

Comment on lines +22 to +26
expect(parseQueryString("sort=newest&color=blue")).toEqual({
sort: "newest",
color: "blue",
});
});

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

Comment on lines +35 to +45
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))
);

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" }},

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

Suggested change
{input:{a : 1, b: 2}, expected:{ 1 : "a" , 2 : "b" }},
{input:{a : 1, b: 1}, expected:/* What happens here? */ },

@MorganDavid MorganDavid added Reviewed Volunteer to add when completing a review and removed Needs Review Participant to add when requesting review labels Jul 12, 2025
	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
@Emilianouz Emilianouz added Needs Review Participant to add when requesting review and removed Reviewed Volunteer to add when completing a review labels Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review Participant to add when requesting review 📅 Sprint 2 Assigned during Sprint 2 of this module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants