Skip to content

Sheffield | 26-Jan-ITP | Daniel Aderibigbe | Sprint 2 | Coursework/sprint 2#1053

Open
Dan2Clouted wants to merge 4 commits intoCodeYourFuture:mainfrom
Dan2Clouted:coursework/sprint-2
Open

Sheffield | 26-Jan-ITP | Daniel Aderibigbe | Sprint 2 | Coursework/sprint 2#1053
Dan2Clouted wants to merge 4 commits intoCodeYourFuture:mainfrom
Dan2Clouted:coursework/sprint-2

Conversation

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

Completed all Exercises.

@Dan2Clouted Dan2Clouted added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 20, 2026
@@ -1,3 +1,5 @@
function contains() {}
function contains(object, property) {
return Object.prototype.hasOwnProperty.call(object, property);
Copy link
Contributor

Choose a reason for hiding this comment

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

  • The function is expected to throw an error or return false when object is not an object or is an array.

  • Could also explore Object.hasOwn().

Comment on lines 48 to +53
// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test("contains with invalid parameters returns false", () => {
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.

expect(contains([], 'a')).toBe(false) may fail to verify whether
contains() can detect its first argument is an array
.

contains([], "a") could also return false because "a" is not a property (or key) of an array.
However, "0", "1", "2" are keys of [1, 2, 3], so it is better to specify the test as
expect(contains([1, 2, 3], "1")).toBe(false); (to ensure you are checking what you describe).

You could also add a few more samples to ensure the function can properly handle arguments of different types.

Comment on lines +11 to +19
const indexOfEquals = pair.indexOf("=");

if (indexOfEquals === -1) {
queryParams[pair] = "";
} else {
const key = pair.slice(0, indexOfEquals);
const value = pair.slice(indexOfEquals + 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.

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")

Note: (You don't have to implement this)

  • 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.

Comment on lines +6 to +14
const result = {};

for (const item of items) {
if (result[item]) {
result[item]++;
} else {
result[item] = 1;
}
}
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.

Comment on lines +29 to +47
function countWords(str) {
const result = {};

if (str.length === 0) {
return result;
}

const words = str.split(" ");

for (const word of words) {
if (result[word]) {
result[word]++;
} else {
result[word] = 1;
}
}

return result;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check if your function returns 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.

@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 21, 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