generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 220
London | 25-ITP-SEP | Adnaan Abo | Sprint 2 | Coursework #807
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
17 commits
Select commit
Hold shift + click to select a range
7f411c4
question answered and code fixed
AdnaanA 3bd2fa8
question answered and code fixed
AdnaanA 6f67742
question answered and code fixed to log ingredients
AdnaanA e384e28
updates
AdnaanA 5aeb947
function fixed with test-cases
AdnaanA 97a9291
created function and testcases for lookups
AdnaanA c7188a0
fixed function to work with all the test-cases in querystring
AdnaanA e90d9dd
fixed function and added test-cases for tally
AdnaanA 01d2170
function fixed and testcases created and tested to pass.
AdnaanA 8aee17e
element name fixed
AdnaanA c8e50b3
contains-test fixed
AdnaanA 9d158ec
fixed contains function and contains-test
AdnaanA 83214e4
fixed prototype issue
AdnaanA 5cf0ffb
changed parameter
AdnaanA 295d8fa
chnaged the contains function
AdnaanA 5d25882
fixed
AdnaanA 131159a
updated
AdnaanA 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
Some comments aren't visible on the classic Files Changed page.
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,16 @@ | ||
| function contains() {} | ||
| // function that checks if a given property exists in an object | ||
| function contains(obj, property) { | ||
| // Check if the input is a valid object and not null or an array | ||
| if ( | ||
| typeof obj === "object" && | ||
| obj !== null && | ||
| !Array.isArray(obj) && | ||
| Object.hasOwn(obj, property) | ||
| ) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| 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,17 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(pairs) { | ||
| /** | ||
| * Creates a lookup object from an array of [key, value] pairs. | ||
| * @param {Array<Array<string>>} pairs - An array of [countryCode, currencyCode] pairs. | ||
| * @returns {Object} - A lookup object mapping country codes to currency codes. | ||
| */ | ||
| if (!Array.isArray(pairs)) { | ||
| throw new TypeError("Argument must be an array of pairs"); | ||
| } | ||
|
|
||
| return pairs.reduce((lookup, [country, currency]) => { | ||
| lookup[country] = currency; | ||
| 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,18 @@ | ||
| function tally() {} | ||
| function tally(items) { | ||
| if (!Array.isArray(items)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| const result = Object.create(null); // Create a clean object with no prototype | ||
|
|
||
| for (const item of items) { | ||
| if (result[item]) { | ||
| result[item]++; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| 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,26 @@ | ||
| const invert = require("./invert"); | ||
|
|
||
| // Test cases for single key-value pair | ||
| test("inverts a single key-value pair", () => { | ||
| expect(invert({ a: 1 })).toEqual({ 1: "a" }); | ||
| }); | ||
|
|
||
| // Test cases for multiple key-value pairs | ||
| test("inverts multiple key-value pairs", () => { | ||
| expect(invert({ a: 1, b: 2 })).toEqual({ 1: "a", 2: "b" }); | ||
| }); | ||
|
|
||
| // Test cases for string values | ||
| test("inverts string values", () => { | ||
| expect(invert({ a: "x", b: "y" })).toEqual({ x: "a", y: "b" }); | ||
| }); | ||
|
|
||
| // Test cases for mixed value types | ||
| test("overwrites keys when values are not unique", () => { | ||
| expect(invert({ a: 1, b: 1 })).toEqual({ 1: "b" }); // last one wins | ||
| }); | ||
|
|
||
| // Test cases for empty object | ||
| test("inverts an empty object", () => { | ||
| expect(invert({})).toEqual({}); | ||
| }); |
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.
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.
These two tests are quite similar.
It would be more useful to test samples with different characteristics. For examples
{a : 'c', b: 2 }to ensure the function won't check the value of the properties.