Sheffield | 26-ITP-Jan | Mahmoud Shaabo | Sprint 2 | Module-Data-Groups#1069
Sheffield | 26-ITP-Jan | Mahmoud Shaabo | Sprint 2 | Module-Data-Groups#1069mahmoudshaabo1984 wants to merge 3 commits into
Conversation
|
Hi CJ, I have just submitted my Pull Request for the Sprint 2 exercises. I really enjoyed the challenges in this sprint, especially learning how to refactor functions and using tools like All tests are passing, and I made sure my comments clearly explain the logic behind the code. I am looking forward to your review and any feedback or suggestions you might have. Thank you! |
cjyuan
left a comment
There was a problem hiding this comment.
This exercise also expects the .test.js files in the "implement" folder to be updated. There are tests to be implemented.
| for (const ingredient of recipe.ingredients) { | ||
| console.log(ingredient); | ||
| } |
There was a problem hiding this comment.
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.
| // Find the position of the FIRST "=" only | ||
| const firstEqualIndex = pair.indexOf("="); | ||
|
|
||
| // If there is no "=", the whole pair is the key with an empty value | ||
| if (firstEqualIndex === -1) { | ||
| queryParams[pair] = ""; | ||
| } else { | ||
| // Everything before the first "=" is the key | ||
| const key = pair.slice(0, firstEqualIndex); | ||
| // Everything after the first "=" is the value (may contain more "=" signs) | ||
| const value = pair.slice(firstEqualIndex + 1); | ||
| queryParams[key] = value; | ||
| } |
There was a problem hiding this comment.
Does your function return the value you expect from the following function call?
parseQueryString("key1=value1&&key2=value2")
| const counts = {}; | ||
|
|
||
| // Loop through each item in the array | ||
| for (const item of items) { | ||
| // If this item already exists in counts, add 1 to it | ||
| // If it does not exist yet, start at 1 | ||
| counts[item] = (counts[item] || 0) + 1; | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
| const sortedCounts = {}; | ||
| for (const [word, count] of sorted) { | ||
| sortedCounts[word] = count; | ||
| } |
There was a problem hiding this comment.
Can also explore using Object.fromEntries() to simplify the code.
| let freqs = new Map(); | ||
|
|
||
| for (let num of list) { |
There was a problem hiding this comment.
Could also consider replacing let by const to further improving the original code.
…ing edge case Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hi CJ, Thank you for the detailed review! I have addressed all your feedback. Here is a summary of the changes: Mandatory fixes:
Optional improvements (also applied):
All 15 tests pass across Looking forward to your feedback! Best regards, |
cjyuan
left a comment
There was a problem hiding this comment.
All other changes look good.
| test("contains returns false when passed an array instead of an object", () => { | ||
| expect(contains(["a", "b"], "a")).toBe(false); | ||
| }); |
There was a problem hiding this comment.
This test does not yet confirm that the function correctly returns false when the first argument is an array.
This is because contains(["a", "b"], "a") could also return false simply because "a" 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.
|
Hi CJ, Great catch — you are absolutely right. The previous test was passing for the wrong reason. I have updated the test to use a valid array index as the key: expect(contains(["a", "b"], "0")).toBe(false);Since "0" is a valid key in the array, the only reason this returns false is because the function correctly rejects arrays. This properly confirms the intended behaviour. All tests are passing. Thank you for the thorough review — I learned something important about writing meaningful tests! Best regards, |
|
Changes look good. Well done. |
|
Closing PR because the January ITP run has finished. Feel free to re-open if you're still working on it. |
Hello Reviewers / CodeYourFuture Team,
I have completed all mandatory and stretch exercises for Sprint 2. I made sure to thoroughly test my code, handle edge cases, and apply refactoring best practices.
Here is a summary of the progress:
address.js,author.js, andrecipe.jsby utilizing proper object iteration (Object.entries,Object.values) and correct property access.contains,lookup, andtally. I also fixed thequerystringfunction usingindexOf("=")andslice()to correctly handle multiple equal signs securely.invert.jsusing bracket notation to dynamically assign keys and values. All analytical questions (a-e) have been clearly answered in the comments.count-words.js: Implemented Regex to remove punctuation, handled case insensitivity, and sorted the final results by frequency.mode.js: Successfully refactored the function into two smaller, single-responsibility functions (countFrequenciesandfindHighestFrequency) utilizing theMapobject.till.js: Fixed theNaNbug by usingparseInt()to accurately extract numerical values from strings.Testing: Verified that all tests across all folders pass successfully using
npx jestand manualnodetesting.Personal Note for the Team:
Working with
Map,Object.entries(), and data type parsing in this sprint greatly improved my understanding of how to safely manipulate complex objects in JavaScript. I have also ensured all my comments explain the "why" behind the code to be fully screen-reader compatible. I look forward to your feedback!Best regards,
Mahmoud Shaabo