Skip to content

Manchester | 26-ITP-Jan | Abdu Hassen | Sprint 2| Data-Grouping#1121

Open
Abduhasen wants to merge 2 commits intoCodeYourFuture:mainfrom
Abduhasen:Data-Group-sprint-2-backlog
Open

Manchester | 26-ITP-Jan | Abdu Hassen | Sprint 2| Data-Grouping#1121
Abduhasen wants to merge 2 commits intoCodeYourFuture:mainfrom
Abduhasen:Data-Group-sprint-2-backlog

Conversation

@Abduhasen
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

Changelist

-debugging of codes
-implementing of codes
-interpreting of codes

Questions

N/A

@Abduhasen Abduhasen 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. Module-Data-Groups The name of the module. labels Mar 27, 2026

for (const value of author) {
console.log(value);
for (const property in 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.

Can also name the variable key -- shorter name.

Comment on lines +14 to +16
for (const element of recipe.ingredients) {
console.log(element);
}
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.

Your code works.

Here is an alternative worth exploring:
Since ingredient values are separated by '\n' in the output, we could also use
Array.prototype.join() to construct the equivalent string and then output the resulting string.

Comment on lines +2 to +8
if (
typeof targetObject !== "object" ||
Object.keys(targetObject).length === 0 ||
Array.isArray(targetObject)
) {
return false;
}
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.

What would happen when targetObject is null?

The check on line 4 is optional. If searchTerm is not a key of the object, the remaining code would also return false.

Comment on lines +10 to +14
for (const property in targetObject) {
if (targetObject[property] === searchTerm || property === searchTerm) {
return true;
}
}
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 function is supposed to check only if it contains searchTerm as its key. There is no need to compare its value.

  • Can also explore Object.hasOwn().

}
return false;
}
console.log(contains(["a", "b", "c"], "d"));
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.

Should delete all unnecessary code to keep the code clean.

Comment on lines +51 to +54
test("the function should return false when invalid parameter like an array is passed", () => {
expect(contains([10, 23, 34, 45], 45)).toBe(false);
expect(contains("hello", "hi")).toBe(false);
expect(contains(["green", "yellow", "rad"], "green")).toBe(false);
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.

This test does not yet confirm that the function correctly returns false when the first argument is an array.
This is because contains([10, 23, 34, 45], 45) could also return false simply because 45 is not a key of the array.

Arrays are objects, with their indices acting as keys. A proper test should use a valid key to ensure the function returns false specifically because the input is an array, not because the key is missing.

Comment on lines 8 to 19
for (const pair of keyValuePairs) {
const [key, value] = pair.split("=");
const equalityPosition = pair.indexOf("=");
if (equalityPosition == -1) {
continue;
}
const key = pair.slice(0, equalityPosition);
const value = pair.slice(equalityPosition + 1);
queryParams[key] = value;
}

return queryParams;
}
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.

These arguments are also valid query strings:

parseQueryString("key1=value1&=&key2=value2")
parseQueryString("key=")
parseQueryString("key1=value1&key2")
parseQueryString("=value")
parseQueryString("key1=value1&&key2=value2")

Comment on lines +2 to +6
if (myArray.length === 0) {
return {};
} else if (typeof myArray === "string") {
throw 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.

  • Why only throw an error when myArray is a string? Why not do the same for other types of data?

  • Why not throw an error when myArray is an empty string?

} else if (typeof myArray === "string") {
throw Error;
}
let tallyObject = {};
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.

@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 1, 2026
@Abduhasen Abduhasen 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 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Data-Groups The name of the module. 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants