Skip to content

London | 26-ITP-May | Alex Jamshidi | Sprint 2 | Exercises#1226

Open
Alex-Jamshidi wants to merge 15 commits into
CodeYourFuture:mainfrom
Alex-Jamshidi:Sprint-2
Open

London | 26-ITP-May | Alex Jamshidi | Sprint 2 | Exercises#1226
Alex-Jamshidi wants to merge 15 commits into
CodeYourFuture:mainfrom
Alex-Jamshidi:Sprint-2

Conversation

@Alex-Jamshidi
Copy link
Copy Markdown

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 exercises for Sprint 2

@Alex-Jamshidi Alex-Jamshidi added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Groups The name of the module. labels May 13, 2026
Copy link
Copy Markdown
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.

Some of the code is not consistently formatted or indented.

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
?

Comment thread Sprint-2/debug/address.js Outdated
};

console.log(`My house number is ${address[0]}`);
console.log(`My house number is ${address.street}, ${address.city}, ${address.country}, ${address.postcode}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your code outputs every parts of an address except the "house number".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added house number.

I had installed prettier and enabled the formatting, however it wasn't working because I hadn't set as my default formatter. I have formatted this code now. (and gone back through all my old PRs and formatted too!)

thanks :)

Comment thread Sprint-2/implement/contains.js Outdated
Comment on lines +2 to +3
if (typeof object !== 'object' || Array.isArray(object)) {return false;}
if (typeof property !== 'string') {return false;}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Line 2 cannot yet reject null.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated to reject null

written tests to confirm

Comment thread Sprint-2/implement/contains.test.js Outdated
Comment on lines +50 to +53
it("given invalid parameter (an array) returns false or throws an error", () => {
const object = [];
const property = [];
expect(contains(object, property)).toEqual(false)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your function can correctly return false when the first argument is an array.

However, we write tests not only to verify our current implementation, but also to ensure that future changes do not alter the function's expected behavior.

The current test cannot yet confirm the function can correctly return false when the first argument is an array
because contains([], []) could also return false simply because [] is not a key of the array.

Arrays are objects, with their indices acting as keys. A proper test should use a non-empty array along with a valid key to ensure the function returns false specifically because the input is an array, not because the key is missing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for this, I understand.

I wrote several tests to cover all options for arrays (filled or empty).

Comment thread Sprint-2/implement/lookup.js Outdated
// implementation here
function createLookup(arrayOfArrays) {
const lookup = {}
for (array of arrayOfArrays) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

array not yet declared.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks, have declared with const

Comment thread Sprint-2/implement/querystring.js Outdated
// currently without adding this database, an unknown PEC could cause the code to get stuck in an infinite loop

function changePEC(string) {
const PEC = {"%24": "$", "%2F": "/"}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are more than two percentage encoded characters.

Consider using the built-in function to decode PEC's in the string instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I didn't know there was a function for this facepalm
I have updated to use the function, it was a lot easier :)

Thanks

Comment thread Sprint-2/implement/querystring.js Outdated
const [key, value] = [pair.slice(0, index), pair.slice(index + 1)]
queryParams[key] = value;
}
else {};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why leave a do-nothing else block in the function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's a good question that doesn't have a good answer, I have removed it.

Thanks

Comment thread Sprint-2/implement/tally.js Outdated
Comment on lines +3 to +8
tally = {}
array.forEach((item) =>{
if (item in tally) {tally[item] += 1}
else tally[item] = 1;
})
return tally
Copy link
Copy Markdown
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, or
  • use Object.hasOwn()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

that was a tough one

Wrote test for case and updated code to pass

@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 May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Data-Groups The name of the module. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants