Skip to content

Conversation

@i786m
Copy link

@i786m i786m commented Nov 2, 2025

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Completed the tasks set out in the debug, implement and interpret folders in sprint 2

@i786m i786m added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 2, 2025
console.log(`${recipe.title} serves ${recipe.serves}
ingredients:
${recipe}`);
${recipe.ingredients}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does not yet satisfy the requirement written on line 6.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 13 to 23
if (Array.isArray(currency)) {
result[country] = currency;
}
if (currency === null || currency === undefined) {
continue;
}

if (country.length && currency.length && typeof country === 'string' && typeof currency === 'string') {
result[country] ? result[country] = [result[country], currency]
: result[country] = currency;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check country.length and type of country on line 20 but not on line 13?

Why check result[country] on line 21 but not on line 14?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amended to include checks, and destructure country and currency

Comment on lines 9 to 18
if(pair.indexOf('=') !== pair.lastIndexOf('=')){
const firstEqualIndex = pair.indexOf('=');
const key = pair.substring(0, firstEqualIndex);
const value = pair.substring(firstEqualIndex + 1);
queryParams[key] = value;
continue;
} else {
const [key, value] = pair.split("=");
queryParams[key] = value;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that in real querystring, both key and value are percent-encoded or URL encoded in the URL. For example, the string "5%" will be encoded as "5%25". So to get the actual value of "5%25" (whether it is a key or value in the querystring), you should call a function to decode it.
May I suggest looking up any of these terms, and "How to decode URL encoded string in JS"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented decoding by calling decodeURIComponent on the string passed

Comment on lines 5 to 8
const result = {};
for (const item of arr) {
result[item] = (result[item] || 0) + 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented Object.create(null) to create an empty object with no inherited properties and test for strings with object methods to confirm there is no unwanted behaviour

Comment on lines 52 to 54
test("should handle array with null and undefined values", () => {
expect(tally([null, undefined, null, 'a', undefined])).toEqual({ null: 2, undefined: 2, a: 1 });
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you expect from the following function call?

tally([null, undefined, null, 'a', undefined, "null", "undefined"]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented test and check for undefined/null vs strings of null/undefined by allocating a separate property for null and undefined values

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 12, 2025
@i786m i786m added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 18, 2025
@i786m i786m requested a review from cjyuan November 18, 2025 20:06
Comment on lines 19 to 29
if (Array.isArray(currency) && typeof country === "string") {
result[country]
? (result[country] = [result[country], currency])
: (result[country] = currency);
}

if (country.length && currency.length && typeof country === 'string' && typeof currency === 'string') {
result[country]
? (result[country] = [result[country], currency])
: (result[country] = currency);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Can you explain why the condition on line 25 needs to check if country.length is non-zero, but the condition on line 19 does not?

  • The normal use of the ? : operator is, condition ? expr1 : expr2, to conditionally evaluates to one of the expressions.

Lines 20-22 is typically expressed as:

  result[country] = result[country] ? [result[country], currency] : currency;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have combined both of the conditions so that the checks apply to both strings and arrays for currency, and have refactored the ternary as suggested.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 18, 2025
i786m and others added 4 commits November 22, 2025 14:42
…and key-value pairs; Implement decoding uri component at key value pair level; update tests for consistency with expected string outputs
…types; update tests for consistency with new key format
@i786m i786m added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 25, 2025
@i786m i786m requested a review from cjyuan November 25, 2025 13:40
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are good.

Comment on lines +22 to +30
test('should return an object', () => {
expect(typeof tally([])).toBe('object');
})
// Given an empty array
// When passed to tally
// Then it should return an empty object
test.todo("tally on an empty array returns an empty object");
test("should return an empty object when given an empty array", () => {
expect(tally([])).toEqual({});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the test on 22-24 necessary?

Comment on lines +19 to +22
if (((Array.isArray(currency) && currency.length)|| (typeof currency === 'string' && currency.length))
&& typeof country === "string" && country.length) {
result[country] = result[country] ? [result[country], currency] : currency;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose before line 19,

  • value of country is "A"
  • value of result[country] is "A1"
  • value of currency is ["A2", "A3"]

What is your expected value of result[country] after line 22?

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 25, 2025
@cjyuan cjyuan added the Complete Volunteer to add when work is complete and all review comments have been addressed. label Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants