Skip to content

London | ITP-May-2025 | Sisay Mehari | Module-Data-Groups | Sprint 2 #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Sisu860
Copy link

@Sisu860 Sisu860 commented Jul 11, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist
✅ Completed Work Summary
This batch of commits includes several key improvements across object handling, function refactoring, string parsing, and utility implementations — all with input validation and test coverage.

🏠 Object Property Access & Iteration
Correctly access the houseNumber property from nested address objects.

Implemented reliable iteration over object property values for better data processing.

Fixed ingredient list logging to output correctly formatted arrays.

🔍 Utility Functions & Parsing
Added a contains function with thorough input validation and comprehensive tests.

Created createLookup function, converting arrays into lookup objects for faster access.

Improved query string parser to correctly handle multiple test cases.

📊 Counting & Frequency Functions
Implemented tally function that counts occurrences with proper parameter handling.

Refined the invert function with added tests and bug fixes for base cases.

Split calculateMode into smaller, focused functions to improve readability and maintainability.

💰 Coin Calculation Fixes
Fixed coin calculation logic by parsing coin keys safely and ignoring invalid entries.

Added tests to ensure robustness against unknown or malformed keys in input objects.

🕒 Recent Commits Highlights
Added a function to count words and return a frequency object with key-value pairs.

Completed breaking down calculateMode into smaller modular functions.

Fixed totalTill function to parse and sum coin values correctly, handling edge cases.

🧪 Testing
Full test coverage added for new and updated functions.

Tests cover edge cases, invalid inputs, and common usage scenarios to ensure reliability.

Questions
None at the moment.

@Sisu860 Sisu860 added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Participant to add when requesting review labels Jul 11, 2025
@hkavalikas hkavalikas added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Participant to add when requesting review labels Jul 19, 2025
@hkavalikas hkavalikas self-requested a review July 19, 2025 06:54
@@ -1,5 +1,7 @@
function createLookup() {
function createLookup(key, value) {
return Object.fromEntries(key, value);
// implementation here

Choose a reason for hiding this comment

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

Minor, but can we move the function implementation under this line for consistency?

Copy link
Author

Choose a reason for hiding this comment

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

I have made the changes.

Choose a reason for hiding this comment

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

Comments like // implement here here OR // TODO: Add X here are pretty handy to follow and search for.
While minor, it's a good idea to follow the instructions where possible and add the solution under those comments e.g. in your case, return Object.fromEntries([[key, value]]);

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the helpful comments. I implemented it in my case.

@@ -1,6 +1,10 @@
const createLookup = require("./lookup.js");

test.todo("creates a country currency code lookup for multiple codes");
test("creates a country currency code lookup for multiple codes", () => {

Choose a reason for hiding this comment

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

Completely optional, but can you think of any other test case worth adding here beyond the happy path one?

Copy link
Author

Choose a reason for hiding this comment

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

I considered multiple test cases.

Choose a reason for hiding this comment

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

Awesome job ✅

Copy link
Author

Choose a reason for hiding this comment

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

Thank you

"category": ["books", "movies", "music"]
})
});
test("parses querystring with empty values", () => {

Choose a reason for hiding this comment

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

What is the difference between the test case here and line 30?

Copy link
Author

Choose a reason for hiding this comment

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

completely the same, I have made the test changes again.

@@ -10,3 +10,28 @@ test("parses querystring values containing =", () => {
"equation": "x=y+1",
});
});

Choose a reason for hiding this comment

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

Can you think of any other test case/scenario we might come across with our application?

Hint: Think of the argument types we can pass to the function, would any type cause unexpected side effects to our flow?

Copy link
Author

Choose a reason for hiding this comment

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

I have fully considered non-string inputs. I added a test case where the function receives a number or null. I updated the function to handle unexpected types more safely.

}

return invertedObj;
}
console.log(invert({ a: 1, b: 2 }));

Choose a reason for hiding this comment

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

Console logs (among other methods) are an awesome way of debugging your code, but most of the time (not a hard rule, but applicable in most cases), it might not be something you want to commit.

Imagine troubleshooting user data with sensitive information and passwords; logging them could end up being a security issue.

Copy link
Author

Choose a reason for hiding this comment

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

I hadn’t thought about the risk of accidentally logging sensitive info. I’ll make sure to remove any debug console.logs before committing code going forward. In this case, I have removed all the console.logs. Thanks for the reminder.

Choose a reason for hiding this comment

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

This covers most of the basic test cases and looks awesome 👏

If I add an additional interesting question, how would your implementation handle duplicate values like { a : 1, b : 2, c : 1 } ?

I suggest trying to come up with an answer before running your code -> expected return type of your current implementation, how would you handle this scenario and finally make any changes/add tests if needed.

Copy link
Author

Choose a reason for hiding this comment

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

I updated the function to check if a value already exists; if it does, it converts it into an array (or adds to it). I also added a new test case to cover that scenario.

@@ -26,3 +26,17 @@

3. Order the results to find out which word is the most common in the input
*/
function countWords(str) {

Choose a reason for hiding this comment

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

Function is looking great, but is it passing all requirements? Specifically,

    - takes a string as an argument
    - returns an object where
          - the keys are the words from the string and
          - the values are the number of times the word appears in the string

Copy link
Author

Choose a reason for hiding this comment

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

The function was returning a sorted array instead of an object. I’ve updated it to return an object where each word is a key and the value is the count. It now meets all the listed requirements.

}


console.log(countWords("you and me and you"));

Choose a reason for hiding this comment

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

Not awfully important but a good habit, please read https://github.com/CodeYourFuture/Module-Data-Groups/pull/583/files#r2217271192

Choose a reason for hiding this comment

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

Sharing for interest purposes only, but in production projects, you usually have tools that will warn/error when certain practices are followed. A good example of that is https://eslint.org/ , an amazing little tool that can check your project for different rules, one of which is this.

Copy link
Author

Choose a reason for hiding this comment

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

That makes a lot of sense.

@@ -21,11 +25,21 @@ const till = {
"20p": 10,
};
const totalAmount = totalTill(till);
console.log(totalAmount);

Choose a reason for hiding this comment

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

Not awfully important but a good habit, please read https://github.com/CodeYourFuture/Module-Data-Groups/pull/583/files#r2217271192

@hkavalikas hkavalikas added Reviewed Volunteer to add when completing a review and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 19, 2025
@Sisu860 Sisu860 added the Needs Review Participant to add when requesting review label Jul 20, 2025
@Sisu860
Copy link
Author

Sisu860 commented Jul 20, 2025

All required changes have been made, I've updated the code and added any missing test cases. Can you please check and put the complete label?

@Sisu860 Sisu860 requested a review from hkavalikas July 20, 2025 12:15
@hkavalikas hkavalikas removed the Needs Review Participant to add when requesting review label Jul 22, 2025
@hkavalikas hkavalikas added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Reviewed Volunteer to add when completing a review labels Jul 22, 2025
@hkavalikas
Copy link

hkavalikas commented Jul 22, 2025

It's quite common to have a little thread/discussion under a PR, especially if there are questions or disagreements with an approach. You can click where it says Reply... on any of my comments and reply there, especially for the comments that ask for a walkthrough/explanation. That way you don't have to commit a comment with your answer (which you might typically not want to do on a production codebase, but that's less important here though)

@hkavalikas
Copy link

Four comments remaining:

@hkavalikas hkavalikas added Reviewed Volunteer to add when completing a review and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jul 22, 2025
@Sisu860
Copy link
Author

Sisu860 commented Jul 22, 2025

It's quite common to have a little thread/discussion under a PR, especially if there are questions or disagreements with an approach. You can click where it says Reply... on any of my comments and reply there, especially for the comments that ask for a walkthrough/explanation. That way you don't have to commit a comment with your answer (which you might typically not want to do on a production codebase, but that's less important here though)

Thanks for the reminder. I’ll make sure to reply directly under your comments next time, especially for those that need a walkthrough or clarification. I appreciate the note about not needing to commit those kinds of responses in a real codebase.

@Sisu860 Sisu860 added the Needs Review Participant to add when requesting review label Jul 22, 2025
@hkavalikas
Copy link

It's quite common to have a little thread/discussion under a PR, especially if there are questions or disagreements with an approach. You can click where it says Reply... on any of my comments and reply there, especially for the comments that ask for a walkthrough/explanation. That way you don't have to commit a comment with your answer (which you might typically not want to do on a production codebase, but that's less important here though)

Thanks for the reminder. I’ll make sure to reply directly under your comments next time, especially for those that need a walkthrough or clarification. I appreciate the note about not needing to commit those kinds of responses in a real codebase.

Awesome, reminder there are a few more things to address:
#583 (comment)

@Sisu860 Sisu860 added Needs Review Participant to add when requesting review and removed Needs Review Participant to add when requesting review labels Jul 23, 2025
@Sisu860
Copy link
Author

Sisu860 commented Jul 23, 2025

I have addressed all the requirements and the changes. I hope this meets the requirement.

@hkavalikas hkavalikas added Complete Volunteer to add when work is complete and review comments have been addressed and removed Needs Review Participant to add when requesting review Reviewed Volunteer to add when completing a review labels Jul 24, 2025
@hkavalikas
Copy link

PR looks great, awesome job ⭐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Complete Volunteer to add when work is complete and review comments have been addressed 📅 Sprint 2 Assigned during Sprint 2 of this module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants