Skip to content

London | 26-ITP-Sep | Maharit Belai | Sprint 2 | coursework/sprint-2 - #1512

Open
MaharitB wants to merge 57 commits into
CodeYourFuture:mainfrom
MaharitB:coursework/sprint-2
Open

MaharitB wants to merge 57 commits into
CodeYourFuture:mainfrom
MaharitB:coursework/sprint-2

Conversation

@MaharitB

@MaharitB MaharitB commented Nov 11, 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

I have done all the course work and created new file for the Invert.js ans have pushed it along with the rest of file

Questions

@MaharitB MaharitB 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 14, 2026
Comment thread Sprint-2/implement/querystring.js Outdated
let [key, ...rest] = pair.split("=");
let value = rest.join("=");

const lastThreeCharKey = key.slice(-3);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is there reason for slicing the last 3 letter word?

are we certain that the key will always contain a 3 character second word?

what if we pass the following input the fn?

parseQueryString("name=John+Doe+Foo&age=30&city=New+York")

is the output correct?

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 have changed it to -2, and why I chose to that because I wanted to differentiate between an equation that hasn't been decoded and a word.
The out put was not correct. Only the first "+" sign was changed. so I made the changes to replace all .

Comment thread Sprint-2/implement/querystring.js Outdated

const lastThreeCharKey = key.slice(-3);
if (!lastThreeCharKey.includes("+") || key.includes("%")) {
key = decodeURIComponent(key.replace("+", " "));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

using a replace will only replace the first occurrence of "+", what if there are more than one occurrences.

is there another fn that replaces all the occurrences of a char?

@hey-hammad hey-hammad 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 14, 2026
@MaharitB MaharitB 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 14, 2026
Comment thread Sprint-2/implement/querystring.js Outdated

const lastThreeCharKey = key.slice(-2);
if (!lastThreeCharKey.includes("+") || key.includes("%")) {
key = decodeURIComponent(key.replaceAll("+", " "));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you're on the right track using replaceAll fn, however there is no need to detect if the key or value contains a "+". Since replaceAll replaces all the instances of "+" we don't need to worry about how many times it appears in the string.

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.

what I am doing right on that if comparison is that I am checking the last two characters, fore example if the key value has an equation like in one of my tests.(a+b+c=x+y+z) so it will check if the last characters include plus sign and then replace it if it is not equation**( first+name, last+name)**. I am not counting rather I am checking. (There is no other way to change +sign even if I decode it).
before I edited the code I used last three to check for equations with an ending of two characters lets say , 2x + 4x. Can you please explain more about what you want me to do here. I need guidance. Thank you .

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Let's take the example of the following input:

a+b+c=x+y+z

What your code does right now

pair = "a+b+c=x+y+z"

line 14   key   = "a+b+c"
line 15   value = "x+y+z"

line 17   lastThreeCharKey = key.slice(-2)   →  "+c"
line 18   !"+c".includes("+")                →  !true  →  false
          key.includes("%")                  →  false
          false || false                     →  false     ← branch skipped
line 19   never runs. key stays "a+b+c"

line 21   lastThreeCharVal = value.slice(-2) →  "+z"
line 22   !"+z".includes("+")                →  !true  →  false     ← branch skipped
line 23   never runs. value stays "x+y+z"

line 25   queryParams["a+b+c"] = "x+y+z"

returns { "a+b+c": "x+y+z" }

Your replaceAll on lines 19 and 23 is correct — it just never executes, because the if above it is false. Compare with name=John+Doe, where "John+Doe".slice(-2) is "oe", the condition is true, and you get {name: "John Doe"}. Same kind of input, opposite result, decided purely by which characters happen to sit at the end.

What the answer should be

new URLSearchParams("a+b+c=x+y+z")   // → { "a b c": "x y z" }
// this is the built-in fn that we're trying to build in this exercise.

In a query string + always means a space — there's no maths-equation exception. A literal plus travels as %2B. In fact a+b+c=x+y+z is exactly what a browser produces when you encode the key a b c with the value x y z:

const p = new URLSearchParams();
p.set("a b c", "x y z");
p.toString();   // "a+b+c=x+y+z"

What I'm suggesting

Delete lines 17, 18, 20, 21, 22 and 24 — both slices, both ifs and the % clause. Keep the two lines you already wrote, running unconditionally:

line 14   key   = "a+b+c"
line 15   value = "x+y+z"

          key   = decodeURIComponent("a+b+c".replaceAll("+", " "))
                  →  "a b c"  →  decode  →  "a b c"
          value = decodeURIComponent("x+y+z".replaceAll("+", " "))
                  →  "x y z"  →  decode  →  "x y z"

          queryParams["a b c"] = "x y z"

And the escaped case still survives, because replaceAll runs before decoding, while %2B is still three plain characters:

          "2x%2B4x".replaceAll("+", " ")   →  "2x%2B4x"   (no "+" to find)
          decodeURIComponent("2x%2B4x")    →  "2x+4x"     ✅

That's the whole reason no detection is needed: replace first, decode second, and the two cases can never collide.

Hope this helps. Thanks

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 very much!! In deed it has. I have made all the necessary changes and all the test pass.

@hey-hammad hey-hammad 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
@MaharitB MaharitB added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 16, 2026
Comment thread Sprint-2/implement/querystring.js Outdated
Comment on lines +17 to +23
const lastThreeCharKey = key.slice(-2);
if (!lastThreeCharKey.includes("+") || key.includes("%")) {
key = decodeURIComponent(key.replaceAll("+", " "));
}
const lastThreeCharVal = value.slice(-2);
if (!lastThreeCharVal.includes("+")) {
value = decodeURIComponent(value.replaceAll("+", " "));

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 happens to a key or value ending in + when its last two characters are checked here, for example in name=Mary+?

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

Comment thread Sprint-2/implement/tally.js Outdated
function tally(arrayItems) {
const countItem = {};
if (!Array.isArray(arrayItems)) {
throw new Error("tally rquires an input");

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 does this error message compare with the invalid-input contract in the test file, and what message do the new tests require?

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

Comment thread Sprint-2/debug/recipe.js
Comment on lines +2 to +3
// My prediction is that ingredients are not gonna be printed out. because the object
// is not attached to the key in the console.log.

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 value does ${recipe} interpolate in the original log statement, and how does that compare with ${recipe.ingredients}?

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 first one will display "[object,object]" when interpolating an object. And when interpolating an array it will log out ingredients list as a string as well

@cyf-ai-code-reviewer cyf-ai-code-reviewer Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label 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.

@MaharitB MaharitB 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 16, 2026
@MaharitB MaharitB added Reviewed Volunteer to add when completing a review with trainee action still to take. 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. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 22, 2026
@MaharitB
MaharitB requested a review from hey-hammad November 22, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants