-
-
Notifications
You must be signed in to change notification settings - Fork 212
Glasgow | 25-ITP-Sep | Abraham-Habte | Sprint 2 | Sprint2-exercise #820
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| function contains() {} | ||
|
|
||
| function contains(object, properityValue){ | ||
| if (typeof object !== 'object' || object === null || Array.isArray(object)) { | ||
| return false; | ||
| } | ||
|
|
||
| return properityValue in object; | ||
|
||
|
|
||
| } | ||
| module.exports = contains; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| function createLookup() { | ||
| function createLookup(pairsArray) { | ||
| // implementation here | ||
| const lookup = Object.fromEntries(pairsArray); | ||
| return lookup; | ||
| } | ||
|
|
||
| module.exports = createLookup; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,23 @@ | ||
| function parseQueryString(queryString) { | ||
|
|
||
| const queryParams = {}; | ||
| if (queryString.length === 0) { | ||
| return queryParams; | ||
| } | ||
| if (!queryString) return queryParams; | ||
|
|
||
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| queryParams[key] = value; | ||
| const index = pair.indexOf("="); | ||
| if (index === -1) { | ||
| queryParams[pair] = undefined; | ||
| } else { | ||
| const key = pair.slice(0, index); | ||
| const value = pair.slice(index + 1); | ||
| queryParams[key] = value; | ||
| } | ||
|
||
| } | ||
|
|
||
| return queryParams; | ||
| } | ||
|
|
||
| module.exports = parseQueryString; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,14 @@ | ||
| function tally() {} | ||
| function tally(input) { | ||
| if (!Array.isArray(input)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| const counts = {}; | ||
| for (let item of input) { | ||
| counts[item] = (counts[item] || 0) + 1; | ||
| } | ||
|
|
||
| return counts; | ||
| } | ||
|
Comment on lines
1
to
12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the following function call returns the value you expect? Suggestion: Look up an approach to create an empty object with no inherited properties. |
||
|
|
||
| module.exports = tally; | ||
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 works (for displaying the properties) to certain extent.
However, I think the objective of this exercise is to practice how to iterate through all the property values of an object. Can you figure out how to use a loop to accomplish that?
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.
got it