Skip to content

London | 26-ITP-May | Rizqah Popoola | Sprint 2 | Data groups - #1323

Open
risikatpopoola wants to merge 2 commits into
CodeYourFuture:mainfrom
risikatpopoola:data-group/sprint-2
Open

London | 26-ITP-May | Rizqah Popoola | Sprint 2 | Data groups#1323
risikatpopoola wants to merge 2 commits into
CodeYourFuture:mainfrom
risikatpopoola:data-group/sprint-2

Conversation

@risikatpopoola

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

@risikatpopoola risikatpopoola added 🏕 Priority Mandatory This work is expected 📅 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 Jul 28, 2026
@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 Aug 1, 2026

@cjyuan cjyuan left a comment

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.

Code is pretty solid.

Note: After our code is working correctly, its a professional practice to change all variable declarations from let to const if they are not going to be reassigned a value.

Comment on lines +2 to +8
for (let index = 0; index < Object.keys(object).length; index++) {
const element = Object.keys(object)[index];
if (element === target) {
return true;
}
}
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.

Code is correct.

Could also consider taking advantage of built-in Array or Object methods to achieve the same behavior with less code.

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.

All the tests in this file have the same description.

If they belong to the same category, you could group the tests into one cateogry.
Otherwise, it's better to give them distinct test descriptions.

Comment on lines 52 to +60
// Given invalid parameters like an array
// When passed to contains
// Then it should return false or throw an error
test("returns true if the object contains the property, false otherwise", () => {
const currentOutput = contains(["a", "b", "c", "e"], "e");
const targetOutput = false;

expect(currentOutput).toEqual(targetOutput);
});

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 quite match the spec given on lines 52-54.

Please note that in JS, an array is a kind of object with its indices serve as its keys.

const [key, value] = pair.split("=");
queryParams[key] = value;
if (pair === "") continue;
const [key = "", value = ""] = pair.split(/=(.*)/);

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.

Interesting approach!

function tally() {}

function tally(array) {
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, or
  • use Object.hasOwn()

Comment on lines +3 to +14
if (Array.isArray(array)) {
for (const item of array) {
if (tallyObject[item] === undefined) {
tallyObject[item] = 1;
} else {
tallyObject[item]++;
}
}
return tallyObject;
} else {
throw new Error("Invalid input");
}

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.

Could consider structuring the code this way:

  if (not an array)
     throw error;

  // code to deal with normal case (no need else)
  ...
``

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. 🏕 Priority Mandatory This work is expected Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants