-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
base: main
Are you sure you want to change the base?
London | ITP-May-2025 | Sisay Mehari | Module-Data-Groups | Sprint 2 #583
Conversation
…ic and edge cases
Sprint-2/implement/lookup.js
Outdated
@@ -1,5 +1,7 @@ | |||
function createLookup() { | |||
function createLookup(key, value) { | |||
return Object.fromEntries(key, value); | |||
// implementation here |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]]);
There was a problem hiding this comment.
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", () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome job ✅
There was a problem hiding this comment.
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", () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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", | |||
}); | |||
}); | |||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Sprint-2/interpret/invert.js
Outdated
} | ||
|
||
return invertedObj; | ||
} | ||
console.log(invert({ a: 1, b: 2 })); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Sprint-2/interpret/invert.test.js
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Sprint-2/stretch/count-words.js
Outdated
} | ||
|
||
|
||
console.log(countWords("you and me and you")); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
modified: Sprint-3/slideshow/slideshow.js modified: Sprint-3/slideshow/style.css
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? |
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 |
…ng Object.fromEntries
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: |
I have addressed all the requirements and the changes. I hope this meets the requirement. |
PR looks great, awesome job ⭐ |
Learners, PR Template
Self checklist
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.