generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Open
zilinskyte
wants to merge
12
commits into
CodeYourFuture:main
Choose a base branch
from
zilinskyte:Coursework/Sprint-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 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 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,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,18 @@ | ||
| 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,17 @@ | ||
| function tally() {} | ||
| function tally(items) { | ||
| if (!Array.isArray(items)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
| const counts = Object.create(null); // empty object to store tally of key-value pairs | ||
| // object.create(null) creates a new object with no inherited properties | ||
| for (const item of items) { | ||
| // iterate through each item in the input array | ||
| const key = String(item); // convert item to string to use as key | ||
| counts[key] = (counts[key] || 0) + 1; // increment count for this key | ||
| } | ||
| return counts; // returns the final counts object | ||
| } | ||
|
|
||
| module.exports = tally; | ||
|
|
||
| console.log(tally(["toString", "toString"])); |
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.
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.
The "current return value" in questions (a), (b), and (d) refers to the value returned by the original (unmodified) function.
The objects you described on line 28 and 31 are not the objects returned by the original function.
The explanation given on line 41 (answer to question (d)) is also not quite correct.
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.
I have rewritten my answer for (d) , I am struggling to understand if you mean my answers to (a) and (b) are incorrect, or if it was just the explanation that was incorrect?