generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 212
West Midlands | ITP-Sept-25 | Georgina Rogers | Sprint 2 | Coursework Sprint 2 #862
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 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
841dc4c
address bug predicted and fixed
zilinskyte c6f3d61
author bug predicted and fixed
zilinskyte b81e384
recipe bug predicted and fixed
zilinskyte c00af0f
contains function - passes 5 cases
zilinskyte 527ecda
lookup function wirtten and tested
zilinskyte 9d2c822
tally function written and tested
zilinskyte 81cbc64
querystring function implemented and tested
zilinskyte 6156a96
improved invert function, added test case file, all questions answered
zilinskyte 97848e5
indentation improved
zilinskyte ba22418
safe decoding of url encoded strings
zilinskyte 2253eff
tally function updated to create empty object with no inherited prope…
zilinskyte 74d46fd
question answer (d) changed
zilinskyte b4f7c9b
answers updated
zilinskyte 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,8 @@ | ||
| function contains() {} | ||
| function contains(obj, prop) { | ||
| if (obj !== null && typeof obj === 'object' && !Array.isArray(obj)) { | ||
| return Object.prototype.hasOwnProperty.call(obj, prop); | ||
| } | ||
| 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,19 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(pairs) { | ||
| // function accepts one parameter: pairs of country-currency code arrays | ||
| if (!Array.isArray(pairs)) { | ||
| return {}; // Return empty object if input is not an array | ||
| } | ||
|
|
||
| const lookup = {}; // Initialize empty lookup object, key-value pairs stored in this object | ||
| for (const pair of pairs) { | ||
| // Iterate over each pair in the input array | ||
| if (Array.isArray(pair) && pair.length >= 2) { | ||
| const [countryCode, currencyCode] = pair; // Destructuring first two elements of pair array and assigning them to country and currency | ||
| lookup[countryCode] = currencyCode; // Add country-currency pair to the lookup object - later entries overwrite earlier ones if duplicate country codes exist. | ||
| } | ||
| } | ||
| 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 counts = {}; // empty object to store tally of key-value pairs | ||
zilinskyte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for (const item of items) { | ||
| // iterates through each element in the items array | ||
| if (counts[item]) { | ||
| // checks if the item already exists as a key in counts object | ||
| counts[item] += 1; // increments the count for that item by 1 | ||
| } else { | ||
| counts[item] = 1; // initializes the count for that item to 1 | ||
| } | ||
| } | ||
| return counts; // returns the final counts object | ||
| } | ||
|
|
||
| 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,22 @@ | ||
| const invert = require('./invert'); | ||
|
|
||
| describe('invert', () => { | ||
| test('inverts a single key', () => { | ||
| expect(invert({ a: 1 })).toEqual({ '1': 'a' }); | ||
| }); | ||
|
|
||
| test('inverts multiple keys', () => { | ||
| expect(invert({ a: 1, b: 2 })).toEqual({ '1': 'a', '2': 'b' }); | ||
| }); | ||
|
|
||
| test('duplicate values: last key wins', () => { | ||
| expect(invert({ a: 1, b: 1 })).toEqual({ '1': 'b' }); | ||
| }); | ||
|
|
||
| test('non-object inputs return empty object', () => { | ||
| expect(invert(null)).toEqual({}); | ||
| expect(invert(undefined)).toEqual({}); | ||
| expect(invert(123)).toEqual({}); | ||
| expect(invert([1, 2, 3])).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.
Uh oh!
There was an error while loading. Please reload this page.