Skip to content

Conversation

@Tarawally
Copy link

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

  • Debug: Fixed property access in address.js, author.js, and recipe.js
  • Implement: Added contains, lookup, tally, and querystring functions with tests
  • Interpret: Answered questions and fixed invert.js

@Tarawally Tarawally added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 29, 2025
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.

Can you revert the changes made in the "Sprint-3" folder to keep this branch clean?


// Handles invalid inputs gracefully
test("contains handles invalid parameters", () => {
expect(contains([], "a")).toBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Arrays are objects in JavaScript, and they do have property names -- just not the same ones as objects.
Which keys do arrays have, and how does that affect how reliable your test is?

When testing whether the function handles arrays properly, try using a key that an array might
realistically contain
. Otherwise, you might get a passing test even if the function isn't checking for arrays at all.

Copy link
Author

@Tarawally Tarawally Dec 9, 2025

Choose a reason for hiding this comment

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

I see that testing for "a" passed simply because that key wasn't there, not because the code was rejecting arrays. Since arrays have a "length" property. I'll update the test to check for that.

Comment on lines +9 to +14
for (const pair of arrayOfPairs) {
const key = pair[0];
const value = pair[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

Could also consider using array destructuring to simplify this 3 lines of code.

Copy link
Author

Choose a reason for hiding this comment

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

I'll remove the need for the temporary key and value' variables inside the loop. I'll refactor it to:

for (const [key, value] of arrayOfPairs) {
    lookupObject[key] = value;
  }

Comment on lines 19 to 22
const firstEqualsIndex = pair.indexOf("=");

const key = pair.slice(0, firstEqualsIndex);
const value = pair.slice(firstEqualsIndex + 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 if the query string is "key1&key2" (i.e., without =)?

const key = pair.slice(0, firstEqualsIndex);
const value = pair.slice(firstEqualsIndex + 1);

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.

In real query string, both key and value are percent-encoded or URL encoded.
For example,

tags%5B%5D=hello%20world -> key is tags[], value is hello world

Can your function handle URL-encoded query string?

Suggestion: Look up "How to decode a URL-encoded string in JavaScript".

Copy link
Author

Choose a reason for hiding this comment

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

No, the current function cannot handle them. I think it would leave characters like %20 encoded.

I'll patch this by wrapping the keys and values in decodeURIComponent, which ensures they are correctly converted back to plain text as a work around.

throw new Error("Input must be an array");
}

const countObject = {};
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.

No, it tries to perform arithmetic on a function, resulting in a broken output.

I'll change this to Object.create(null).

@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 29, 2025
@Tarawally
Copy link
Author

Yep, sure. I thought I’d checked out another branch.

@Tarawally Tarawally force-pushed the sprint-2 branch 3 times, most recently from 627293b to 587720a Compare December 10, 2025 03:37
@Tarawally
Copy link
Author

I'll be opening a new pr because i'm having issues with git subtree and the commit history

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants