-
-
Notifications
You must be signed in to change notification settings - Fork 153
LONDON | 25-ITP-MAY | TEWODROS BEKERE | M-D-G | SPRINT-2 #674
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
…2/debug/address.js
…print-2/author.js
…le on it for sprint 2
…nal to fix that i updated the package.jason
…ccuracy for M-D-G/Sprint-2/implement/lookup.js
… pairs and update tests for accuracy for M-D-G/Sprint-2/implement/querystring.js
…ing tests for M-D-G/Sprint-2/implement/tally.js
… and add test cases for M-D-G/Sprint-2/interpret/invert.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.
Overall this is very good. You're making great progress. I've made some comments and suggestions.
const keyValuePairs = queryString.split("&"); | ||
|
||
for (const pair of keyValuePairs) { |
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.
How will code cope with invalid input like &name=Zadie&
or city=London&&year=2025
?
key = decodeURIComponent(pair.substring(0, index)); | ||
value = decodeURIComponent(pair.substring(index + 1)); | ||
} else { | ||
key = decodeURIComponent(pair); |
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 will happen if string passed to decodeURIComponent
is not a well-formed URI?
if (obj.hasOwnProperty(key)) { | ||
return true; | ||
} else { | ||
return false; | ||
} |
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.
Do we need an if/else
here? How could we simplify this?
function tally(items) { | ||
if (!Array.isArray(items)) { | ||
throw new Error("Input must be an array"); | ||
} | ||
|
||
const counts = {}; | ||
|
||
for (let i = 0; i < items.length; i++) { | ||
const item = items[i]; | ||
if (counts[item]) { | ||
counts[item]++; | ||
} else { | ||
counts[item] = 1; | ||
} | ||
} | ||
|
||
return counts; | ||
} |
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.
Your current solution works well! For future reference, this is a common use case for the reduce()
method, which is designed specifically for accumulating values from arrays. If you're interested in exploring an alternative approach, reduce()
could make this more concise.
No changes needed—just something to keep in mind for similar problems.
const { test } = require("picomatch"); | ||
|
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.
Solution is good and explanations are clear. However I'm not sure why you are importing picomatch
. Please put your tests in a separate file - invert.test.js
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Questions
Ask any questions you have for your reviewer.