Skip to content

London | 26-ITP-Sep | Shirin Panahian | Sprint 2| Complete sprint 2 exercises - #1516

Open
shirinpanahian wants to merge 10 commits into
CodeYourFuture:mainfrom
shirinpanahian:Sprint-2
Open

shirinpanahian wants to merge 10 commits into
CodeYourFuture:mainfrom
shirinpanahian:Sprint-2

Conversation

@shirinpanahian

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

Task code

CYF-1083

Changelist

This PR includes my work for Sprint 2 of the Module Data Groups project.

  • Debug: Analysed the existing code, predicted and explained the bugs, ran the files using Node.js, and fixed the issues.
  • Implement: Worked on implementing functions based on the provided requirements, including contains, lookup, tally, and querystring. Tested the functions with different inputs to verify their behaviour.
  • Interpret: Worked through the provided programs to understand unfamiliar JavaScript syntax, operators, and functions using documentation and console.log().

This sprint helped me improve my JavaScript problem-solving, debugging, implementation, and code-reading skills.

@shirinpanahian shirinpanahian added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 2 Assigned during Sprint 2 of this module labels Nov 12, 2026
@valentina-starr1

Copy link
Copy Markdown

Thank you for this PR. Great work completing the Sprint 2 exercises and adding tests.

I can see two small JavaScript edge cases to fix before merging:

tally.js (line 12): Plain objects inherit built-in keys like toString, so tally(["toString"]) tries to add 1 to a function instead of returning { toString: 1 }. Using Object.hasOwn() or Object.create(null) fixes this.

querystring.js (line 38): Assigning "proto" directly to a normal object changes its prototype instead of saving it as a key. Using Object.create(null) or Object.defineProperty() handles it safely.

@shirinpanahian

Copy link
Copy Markdown
Author

Thank you for the feedback and the helpful explanations!

I've fixed both edge cases using Object.hasOwn() in tally.js and Object.create(null) in querystring.js.

I've also added tests to cover these cases and pushed the updates to the PR.

Thanks again for the review!

Thank you for this PR. Great work completing the Sprint 2 exercises and adding tests.

I can see two small JavaScript edge cases to fix before merging:

tally.js (line 12): Plain objects inherit built-in keys like toString, so tally(["toString"]) tries to add 1 to a function instead of returning { toString: 1 }. Using Object.hasOwn() or Object.create(null) fixes this.

querystring.js (line 38): Assigning "proto" directly to a normal object changes its prototype instead of saving it as a key. Using Object.create(null) or Object.defineProperty() handles it safely.

@shirinpanahian shirinpanahian added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 12, 2026
@LonMcGregor LonMcGregor added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 16, 2026
if (Object.hasOwn(tallyObj, item)) {
tallyObj[item] = tallyObj[item] + 1;
} else {
tallyObj[item] = 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What own property does the {} accumulator get when an input item is "__proto__"? Try tally(["__proto__"]) and compare the result with the requirement to count every item.

To "like" or "dislike" this comment, please follow this link

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.

Good catch! When using {} as the accumulator, __proto__ is treated as a special property rather than a normal own property. This means tally(["__proto__"]) does not correctly count the item. I've fixed this by using Object.create(null) to create an accumulator without a prototype, allowing __proto__ to be counted as a normal key.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For your future reference, the proper way to fix this AI's review is to use tallyObj.hasOwnProperty(item) which would not modify nor create side effect to the prototype definition.

Comment thread Sprint-2/implement/lookup.js Outdated
Comment on lines +8 to +13
console.log(
createLookup([
["US", "USD"],
["CA", "CAD"],
])
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What appears in the test process output when lookup.test.js requires this module?

To "like" or "dislike" this comment, please follow this link

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've removed the console.log() so requiring the module no longer produces unexpected output.

Comment thread Sprint-2/implement/contains.test.js Outdated
Comment on lines +43 to +46
test("given an object, returns true as the object contains a key of 'a'", function () {
const input = contains({ a: 1, b: 2 }, "c");
const currentOutput = input;
const targetOutput = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How do the descriptions for the "c", numeric, null, and missing-argument cases compare with their inputs and assertions?

To "like" or "dislike" this comment, please follow this link

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 pointing this out. Some of the test descriptions didn't match their actual inputs and assertions. I've updated them so the "c" case describes returning false for a missing property, the numeric case describes receiving a number, the null case describes receiving null, and the missing-argument case describes being called without an argument.

Comment thread Sprint-2/debug/author.js
console.log(author[value]);
}
//author is Object and it is not iterable
//for...of loop excepts array and string but it not working with object type

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Besides arrays and strings, what other iterable types can a for...of loop handle?

To "like" or "dislike" this comment, please follow this link

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.

Besides arrays and strings, for...of can iterate over Maps, Sets, TypedArrays, Generators and other iterable objects such as NodeLists.

A normal object isn't iterable by default, which is why for...of doesn't work directly with author. We can use for...in to iterate over its property keys, or Object.values(author) to get its values and iterate over them using for...of.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your explanation is correct. Just the typo makes AI misunderstood your comment: should be expects but not excepts.

@cyf-ai-code-reviewer cyf-ai-code-reviewer Bot 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 16, 2026
@cyf-ai-code-reviewer

Copy link
Copy Markdown

The CYF AI review has left comments. It will only review a PR one time. When you have addressed these comments, please request review again and a volunteer will take a look.

@shirinpanahian shirinpanahian 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, 2026
@hackertainment hackertainment added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 22, 2026

@hackertainment hackertainment left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good work. Code/comment change required for the following 3 files:

  • Sprint-2/debug/address.js
  • Sprint-2/debug/recipe.js
  • Sprint-2/implement/contains.test.js‎

Other review comments are for your future improvement. Thank you.

Comment thread Sprint-2/debug/address.js Resolved
Comment thread Sprint-2/debug/author.js
console.log(author[value]);
}
//author is Object and it is not iterable
//for...of loop excepts array and string but it not working with object type

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your explanation is correct. Just the typo makes AI misunderstood your comment: should be expects but not excepts.

Comment thread Sprint-2/debug/recipe.js
@@ -1,8 +1,8 @@
// Predict and explain first...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please add your prediction and explanation as comment into the code (similar to author.js). Thank you.

Comment on lines +2 to +4
// if (cont === "") {
// return false;
// }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

please remove unused code in the future. Thank you.

test.todo("contains on empty object returns false");
describe("contains", () => {
test("given an empty object, returns false", function () {
const input = contains({}, "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good that you can think of this boundary test case. Well done!

Comment on lines +50 to +80
// Given a value that isn't an object - an array, a string, a number,
// null, or no argument at all
// When passed to contains
// Then it should throw Error("contains requires an object")
// (careful: typeof [] and typeof null are both "object")
it("throws when given an array containing a value that isn't an object", () => {
expect(() => contains(["banana"])).toThrow(
new Error("contains requires an object")
);
});
it("throws when given a number", () => {
expect(() => contains(123)).toThrow(
new Error("contains requires an object")
);
});

it("throws when given null", () => {
expect(() => contains(null)).toThrow(
new Error("contains requires an object")
);
});

it("throws when called without an argument", () => {
expect(() => contains()).toThrow(new Error("contains requires an object"));
});

it("throws when given an empty array", () => {
expect(() => contains([])).toThrow(
new Error("contains requires an object")
);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since contains() accepts two mandatory arguments, the test cases should have a proper second argument (even the first argument isn't an object).

Also, a string as first argument is missed in the error cases, and please add it as well. Thank you.

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.

Thank you for your feedback. I've updated the test cases to include the second argument in all cases I'll run the tests again to make sure everything works correctly.

Comment on lines +6 to +8
if (arr.length === 0) {
return {};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For your future reference, these 3 lines are not needed, because line 2 initialised tallyObj as an empty {}, and the for-of loop in line 11 will not run when arr is empty, which results in empty {} to be returned correctly in line 18.

if (Object.hasOwn(tallyObj, item)) {
tallyObj[item] = tallyObj[item] + 1;
} else {
tallyObj[item] = 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For your future reference, the proper way to fix this AI's review is to use tallyObj.hasOwnProperty(item) which would not modify nor create side effect to the prototype definition.

@hackertainment hackertainment added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Nov 22, 2026
Added prediction and explanation comments for code behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants