Skip to content

West Midlands | 26-Jan-ITP | Fida Ali Zada | Sprint 2 | Data Group#985

Open
alizada-dev wants to merge 14 commits intoCodeYourFuture:mainfrom
alizada-dev:coursework/sprint-2
Open

West Midlands | 26-Jan-ITP | Fida Ali Zada | Sprint 2 | Data Group#985
alizada-dev wants to merge 14 commits intoCodeYourFuture:mainfrom
alizada-dev:coursework/sprint-2

Conversation

@alizada-dev
Copy link
Copy Markdown

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 the exercises in the Sprint-2 folder

@alizada-dev alizada-dev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 9, 2026
};

for (const value of author) {
for (const [key, value] of Object.entries(author)) {
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.

Since this loop does not need key, you could consider using the method that returns only an array of property values.

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.

for (const value of Object.values(author)) { console.log(value); }

Comment on lines +2 to +3
for (const key in obj) {
if (Object.hasOwn(obj, key) && key == x) {
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 check if key is in the same object the loop is iterating though?

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.

for (const key in obj) { if (key == x) { return true } }

// Then it should return false or throw an error

test("contains on invalid parameters returns false", () => {
expect(contains(["a", "b", "c"])).toStrictEqual(false);
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Mar 20, 2026

Choose a reason for hiding this comment

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

Does your function return the value you expect from the following function calls?

contains(["a", "b", "c"], "1")
contains("abc", "1")
contains(null, "1")
contains(undefined, "1")

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.

Now, it handles correctly.

const value = pair.substring(index + 1);

queryParams[key] = value;
}
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.

For each of the following function calls, does your function return the value you expect?

parseQueryString("a=b&=&c=d")
parseQueryString("a=")
parseQueryString("=b")
parseQueryString("a=b&&c=d")
parseQueryString("a%25b=c%26d")

Note:

  • In real query string, both key and value are percent-encoded or URL encoded in the URL.
    For example, the string "5%" is encoded as "5%25". So to get the actual value of "5%25"
    (whether it is a key or value in the query string), we need to call a function to decode it.

  • You can also explore the URLSearchParams API.

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.

`function parseQueryString(queryString) {
const queryParams = {};

if (!queryString) return queryParams;

const keyValuePairs = queryString.split("&");

for (const pair of keyValuePairs) {
// skip empty pairs (e.g. &&)
if (pair === "") continue;

const index = pair.indexOf("=");

let key, value;

if (key === -1) {
  key = pair;
  value = "";
} else {
  key = pair.substring(0, index);
  value = pair.substring(index + 1);
}

// decoding URL
try {
  key = decodeURIComponent(key);
  value = decodeURIComponent(value);
} catch (error) {
  
}

queryParams[key] = value;

}

return queryParams;
}`

return countObj;
}

else throw new Error("");
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.

Can you give a more descriptive error message?

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.

else throw new Error("The input should be an array!");

Comment on lines +4 to +13
let countObj = {};

for (const item of arr) {

if (countObj[item]) {
countObj[item] = countObj[item] + 1;
} else {
countObj[item] = 1;
}
}
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.

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.

`function tally(arr) {
if (!Array.isArray(arr)) {
throw new Error("The input should be an array!");
}

const countObj = Object.create(null);

for (const item of arr) {

    if (countObj[item]) {
        countObj[item] = countObj[item] + 1;
    } else {
        countObj[item] = 1;
    }
}

return countObj;

}`

Comment on lines +25 to +26
// c) What is the target return value when invert is called with {a : 1, b: 2}
// { key: 2 }
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.

The "target value" refers to the expected value when the function is working correctly.

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.

{1 : 'a', 2: 'b'}

return Object.fromEntries(sortedArray);
}

console.log(countWords("you? and! me, and you. me me me me hello Me"));
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 your function return what you expect in the following function calls?

countWords("Hello,World! Hello World!");
countWords("constructor constructor");
countWords("          Hello World      ");

Note: The spec is not clear about exactly what to expect from these function calls. This is just for self-check.

Comment on lines 27 to +28
// a) What is the target output when totalTill is called with the till object
// £NaN
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.

I think the question is asking for the "expected output", not the actual output.

@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 Mar 20, 2026
@alizada-dev
Copy link
Copy Markdown
Author

I am sorry, sir, for responding late. I got a job because it was so stressful not working.

@alizada-dev alizada-dev 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 Apr 2, 2026
@cjyuan
Copy link
Copy Markdown
Contributor

cjyuan commented Apr 3, 2026

The proposed changes look good. Have you applied the changes and pushed the changes to GitHub? I don't see any new commits on this PR branch.

@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 Apr 3, 2026
@alizada-dev
Copy link
Copy Markdown
Author

I had forgotten to push the changes. I just pushed them.

@alizada-dev alizada-dev 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 Apr 4, 2026
@cjyuan
Copy link
Copy Markdown
Contributor

cjyuan commented Apr 4, 2026

Still nothing new on this branch. Did you push the changes on the right branch?

@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 Apr 4, 2026
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