Skip to content

London | 26-ITP-Sep | Alan Mak | Sprint 2 | Sprint 2 Coursework - #1590

Open
AlanGit-debug2604 wants to merge 11 commits into
CodeYourFuture:mainfrom
AlanGit-debug2604:Sprint2
Open

AlanGit-debug2604 wants to merge 11 commits into
CodeYourFuture:mainfrom
AlanGit-debug2604:Sprint2

Conversation

@AlanGit-debug2604

@AlanGit-debug2604 AlanGit-debug2604 commented Dec 2, 2026 •

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

Completed the Sprint 2 exercises, including debugging and implementing the required functions.

@AlanGit-debug2604 AlanGit-debug2604 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. labels Dec 2, 2026
Comment thread Sprint-2/debug/address.js
Comment on lines +2 to +5
// The code will print 'My house number is undefined',
// because the template literal attempts to access the houseNumber property as if it were an array element.
// But this is not the correct way to access object properties.
// The correct syntax is to use dot notation or bracket notation without the extra brackets.

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 property does the original address[0] expression read, and how does that compare with this explanation?

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.

It does not read as housenumber , address[0] treid to read as a property named '0'

Comment on lines +31 to +32
// The current return value is different from the target output because the original implementation of invert was not correctly swapping the keys and values.
// It may have been returning the original object or not handling the key-value pairs properly. The corrected implementation uses Object.entries to iterate over the key-value pairs and constructs a new object with the keys and values swapped, resulting in the desired output.

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 result would the original invertedObj.key = value assignment produce for an object with two properties, and does that match this explanation?

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.

The values 1 and 2 become string property keys. This matches the explanation: invertedObj[value] = key correctly swaps keys and values. It does not match the claim that the current implementation returns the original object or fails to handle pairs.

@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 Dec 2, 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.

@AlanGit-debug2604 AlanGit-debug2604 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 2, 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. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Dec 3, 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.

Thank you for your coursework. If you need more practice on object/dictionary in JavaScript, please feel free to book a mentored coding session with a volunteer.

Comment thread Sprint-2/debug/author.js
for (const value of author) {
console.log(value);
for (const [key, value] of Object.entries(author)) {
console.log(`${key}: ${value}`);

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 reference only, it just needs to print out the values, so console.log(value); is correct.

throw new Error("contains requires an object");
}

return Object.prototype.hasOwnProperty.call(object, propertyName);

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, whenever possible, do not use prototype function directly. You may simply use return object.hasOwn(propertyName); instead to achieve the same result. Thank you.

Comment on lines +15 to +23
test("creates a lookup for a single code pair", () => {
expect(createLookup([["GB", "GBP"]])).toEqual({
GB: "GBP",
});
});

test("returns an empty object when passed an empty array", () => {
expect(createLookup([])).toEqual({});
});

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 test case coverage!

Comment on lines +21 to +26
Object.defineProperty(queryParams, key, {
value,
enumerable: true,
configurable: true,
writable: true,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This will add a property to all Objects of the same type globally (basically everything in JavaScript) but not solely for the queryParams object. Please fix it. Thank you.

Comment on lines +62 to +68
test("should safely parse a __proto__ key", () => {
const result = parseQueryString("__proto__=safe");

expect(Object.prototype.hasOwnProperty.call(result, "__proto__")).toBe(true);
expect(result.__proto__).toBe("safe");
expect(Object.getPrototypeOf(result)).toBe(Object.prototype);
});

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 the same reason from my other comments, please try to fix this test case by not accessing prototype directly. Thank you.

Comment on lines +12 to +17
Object.defineProperty(counts, item, {
value: 1,
enumerable: true,
configurable: true,
writable: true,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This will add a property to all Objects of the same type globally (basically everything in JavaScript) but not solely for the counts object. Please fix it. Thank you.

Comment on lines +21 to +24
// a) What is the current return value when invert is called with { a : 1 }
// {1: "a"}
// b) What is the current return value when invert is called with { a: 1, b: 2 }

//{"1": "a", "2": "b"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It is asking about the original code before fixing, but not the one after fixed. What would be the result for (a) and (b)? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants