-
-
Notifications
You must be signed in to change notification settings - Fork 149
London | ITP-May-2025 | Seddiq Azam | Module-Data-Groups | Sprint 2 #578
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?
Conversation
created new file called mean.test.js: prep/mean.test.js created new file called mean.js
deleted: prep/mean.test.js
…t-2/debug/address.js
modified: Sprint-2/implement/contains.test.js deleted: Sprint-2/package-lock.json deleted: Sprint-2/package.json
deleted: Sprint-3/package.json
modified: Sprint-2/implement/lookup.test.js
modified: Sprint-2/implement/lookup.test.js
…uerystring.js modified: Added test to check the new function Sprint-2/implement/querystring.test.js
modified: Sprint-2/implement/tally.test.js
…nd getMostFrequentValue for improved readability and maintainability
…by converting coin strings to numbers
The package.json file was mistakenly changed.
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.
Code is good. Good job! I manly have some suggestions.
queryParams[pair] = ""; | ||
} else { | ||
const key = pair.slice(0, firstEqualIndex); | ||
const value = pair.slice(firstEqualIndex + 1); | ||
queryParams[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.
Please note that in real querystring, both key
and value
are percent-encoded or URL encoded in the URL. For example, the string "5%" will be encoded as "5%25". So to get the actual value of "5%25" (whether it is a key or value in the querystring), you should call a function to decode it.
May I suggest looking up any of these terms, and "How to decode URL encoded string in JS"?
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.
Character | Encoded As | Reason |
---|---|---|
% |
%25 |
Starts an encoded sequence, must be escaped itself |
(space) |
%20 |
Spaces are not allowed in URLs |
& |
%26 |
Separates query parameters |
= |
%3D |
Assigns values to keys |
? |
%3F |
Starts a query string |
! |
%21 |
Reserved character, often escaped |
/ |
%2F |
Used in paths, escaped in values |
# |
%23 |
Starts a URL fragment |
" |
%22 |
Double quotes must be escaped |
' |
%27 |
Single quotes can cause parsing issues |
: |
%3A |
Used in protocols (e.g., http: ) |
+ |
%2B |
May be interpreted as space in form data |
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.
There are built-in functions you can use to decode the percent-encoded key and value at lines 14 and 18.
…ed output in tests
…unrecognized coins
Merge branch 'main' into Sprint-2 What happened 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.
const coinValues = { | ||
"1p": 10, | ||
"5p": 6, | ||
"50p": 4, | ||
"20p": 10, | ||
}; | ||
const totalAmount = totalTill(till); | ||
|
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 variable at line 34 should be kept as till
. The property values represent the number of coins.
The coinValues
to be used as a lookup table is supposed to represent the value of each coin.
And since the lookup table is used locally within the function, you can write
function totalTillAlternative(till) {
const coinValues = {
"1p": 1,
"5p": 5,
"50p": 50,
"20p": 20,
};
let total = 0;
// Code to calculate total ...
return `£${(total / 100).toFixed(2)}`;
}
function totalTillAlternative(till) { | ||
let total = 0; | ||
|
||
for (const [coin, quantity] of Object.entries(till)) { | ||
// Convert coin to a number and multiply by quantity | ||
total += coinValues[coin] * quantity; | ||
|
||
if (!coin in coinValues) { | ||
throw new Error(`Coin ${coin} is not recognized`); | ||
} | ||
|
||
return `£${(total / 100).toFixed(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.
You didn't have to delete your original implementation, you could just implement a new function.
Anyway, this totalTillAlternative()
is similar to totalTill()
(why keep two similar copies?), and it has a bug.
queryParams[pair] = ""; | ||
} else { | ||
const key = pair.slice(0, firstEqualIndex); | ||
const value = pair.slice(firstEqualIndex + 1); | ||
queryParams[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.
There are built-in functions you can use to decode the percent-encoded key and value at lines 14 and 18.
You must title your PR like this:
REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME
For example,
London | May-2025 | Carol Owen | Quote-generator
Complete the task list below this message.
If your PR is rejected, check the task list.
-->
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
This pull request includes debugging fixes, implementation improvements, and testing updates across multiple files in Sprint-2 and Sprint-3. Key changes include resolving bugs in object property handling, enhancing functionality for utility functions, and adding comprehensive test cases to ensure correctness. Below is a categorized summary of the most important changes:
Debugging Fixes:
address.js
: Fixed a bug whereaddress.houseNumber
was incorrectly accessed asaddress[0]
. Updated the code to properly define theaddress
object and access its properties. [1] [2]author.js
: Corrected the iteration over object properties by replacingfor...of
withObject.values()
to handle non-iterable objects. [1] [2]recipe.js
: Adjusted the logging of recipe ingredients by iterating over the array and joining them with newlines for proper formatting. [1] [2]Implementation Enhancements:
contains.js
: Implemented thecontains
function to check for object properties with safety checks for invalid inputs.lookup.js
: Added thecreateLookup
function to generate a key-value mapping from an array of pairs.querystring.js
: Fixed edge cases inparseQueryString
, such as handling keys without values, and updated the test suite. [1] [2]tally.js
: Implemented thetally
function to count occurrences of items in an array, with error handling for invalid inputs. [1] [2]invert.js
: Corrected theinvert
function to dynamically swap object keys and values and added explanatory comments.Testing Improvements:
contains.test.js
: Added comprehensive tests for thecontains
function, covering valid and invalid inputs, empty objects, and edge cases.lookup.test.js
: Added a test forcreateLookup
to validate the output structure and correctness.tally.test.js
: Expanded test coverage for thetally
function, including cases for empty arrays, duplicate items, and invalid inputs.Stretch Goals:
count-words.js
: Implemented a function to count word occurrences in a string, including handling empty or whitespace-only strings.mode.js
: RefactoredcalculateMode
by splitting it into smaller functions for frequency calculation and finding the most frequent value. [1] [2]till.js
: Fixed and added an alternative implementation fortotalTill
to correctly calculate total amounts in pounds, with detailed explanations and tests. [1] [2]Questions
Ask any questions you have for your reviewer.