-
-
Notifications
You must be signed in to change notification settings - Fork 283
London | 26-ITP-January | Eugenie Ahangama | Sprint 2 | Data Groups #983
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
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
14a2f59
Fixed object property access using dot notation + added prediction an…
Eugenie-A ebab27d
Fixed non-iterable object with Object.values + added prediction and e…
Eugenie-A af62090
Fixed object interpolation, loop ingredients + added prediction and e…
Eugenie-A 4c8181e
Updated my prediction and explanation for this problem
Eugenie-A e5a0167
Updated the prediciton and explanation of this problem
Eugenie-A 461e87e
Added tests for contains function
Eugenie-A 371eb7e
Added contains.js implementation
Eugenie-A 21e1adc
Added tests for the lookup function
Eugenie-A 9e7a052
Implemented lookup.js function
Eugenie-A 5bd4e7e
Fixed parseQueryString value parsing + filter empty pairs
Eugenie-A 6b31d1d
fix: split on first = only to correctly parse values containing =
Eugenie-A a4b781b
test: added edge case tests for parseQueryString and fixed typo in ag…
Eugenie-A 8953ba6
Added implementation for tally
Eugenie-A 17d8641
added test cases to reflect the function
Eugenie-A 86ed817
Answered a to d questions
Eugenie-A ddd29d3
Fix: Added missing module.exports to invert
Eugenie-A e604821
Answered question e
Eugenie-A 846db55
Added test cases for invert.js
Eugenie-A cbcbe64
Fix: Use Object.hasOwn instead of hasOwnProperty
Eugenie-A 1962dc2
Fix: Use Object.create(null) to avoid inherited property conflicts
Eugenie-A 827f5b3
Fix: Add more invalid input types to invert tests
Eugenie-A 0eebfb8
Fix: Decode percent-encoded keys and values in parseQueryString
Eugenie-A File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| function contains() {} | ||
| function contains(object, propertyName) { | ||
| // return false if object is null/defined or not an object | ||
| if (object == null) return false; | ||
| // typeof check + reject arrays | ||
| if (typeof object !== "object") return false; | ||
| if (Array.isArray(object)) return false; | ||
|
|
||
| // Use Object.hasOwn to check only own properties | ||
| return Object.hasOwn(object, propertyName); | ||
| } | ||
|
|
||
| module.exports = contains; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,16 @@ | ||
| function createLookup() { | ||
| function createLookup(pairs) { | ||
| // implementation here | ||
| // Creates empty object that will store our, | ||
| // country → currency | ||
| const lookup = {}; | ||
| // Loop through each pair in the input array | ||
| for (const [country, currency] of pairs) { | ||
| // Use the country code as they key | ||
| // Assigns the correspoding currency code as the value | ||
| lookup[country] = currency; | ||
| } | ||
| // returns the completed lookup object | ||
| return lookup; | ||
| } | ||
|
|
||
| module.exports = createLookup; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,23 @@ | ||
| function tally() {} | ||
| function tally(arr) { | ||
| // Check if the input is not an array | ||
| if (!Array.isArray(arr)) { | ||
| // If it's not an array, stop the function | ||
| // and throw an error message | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| // Create an empty object with no inherited properties | ||
| // This prevents conflicts with built in properties like "toString" | ||
| const counts = Object.create(null); | ||
|
|
||
| // Loop through each item in the array one by one | ||
| for (const item of arr) { | ||
| // If the item already exists in counts, add 1 to it | ||
| // If it doesn't exist yet (undefined), start it at 0 then add 1 | ||
| counts[item] = (counts[item] || 0) + 1; | ||
| } | ||
| // Return the finished counts object once all items have been tallied | ||
| return counts; | ||
| } | ||
|
|
||
| module.exports = tally; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| const invert = require("./invert.js"); | ||
|
|
||
| // Given an object | ||
| // When invert is passed this object | ||
| // Then it should swap the keys and values | ||
| test("invert swaps the keys and values of an object", () => { | ||
| expect(invert({ x: 10, y: 20 })).toEqual({ | ||
| 10: "x", | ||
| 20: "y", | ||
| }); | ||
| }); | ||
|
|
||
| // Given an object with one key value pair | ||
| // When passed to invert | ||
| // Then it should return the swapped pair | ||
| test("invert swaps a single key value pair", () => { | ||
| expect(invert({ a: 1 })).toEqual({ | ||
| 1: "a", | ||
| }); | ||
| }); | ||
|
|
||
| // Given an empty object | ||
| // When passed to invert | ||
| // Then it should return an empty object | ||
| test("invert on an empty object returns an empty object", () => { | ||
| expect(invert({})).toEqual({}); | ||
| }); | ||
|
|
||
| // Given an invalid input like an array, string, number, null or undefined | ||
| // When passed to invert | ||
| // Then it should throw an error | ||
| test("invert throws an error for invalid input", () => { | ||
| expect(() => invert([])).toThrow("Input must be an object"); | ||
| expect(() => invert("hello")).toThrow("Input must be an object"); | ||
| expect(() => invert(123)).toThrow("Input must be an object"); | ||
| expect(() => invert(null)).toThrow("Input must be an object"); | ||
| expect(() => invert(undefined)).toThrow("Input must be an object"); | ||
| }); | ||
|
cjyuan marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.