-
-
Notifications
You must be signed in to change notification settings - Fork 327
London | 26-ITP-May | Jorvan White | Sprint 2 | Coursework #1418
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
JorvanW
wants to merge
23
commits into
CodeYourFuture:main
Choose a base branch
from
JorvanW: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
23 commits
Select commit
Hold shift + click to select a range
2c983b7
Updated code for median.js to pass the late expectations
6c109e9
Added code to dedupe.js
d57add3
added code for max.js
e3befbb
Added code to sum.js
872ddf0
modified code on includes.js to use a for...of loop
6c28930
Changed code in address. js to specify houseNumber
bbf0a73
Updated code and added notes for author.js
5c2b4b5
update the code and added notes to recipe.js
663412b
Added code and tests for contains.js
4c0d767
added code to lookup.test
827b052
added code and passed tests for querystring.test.js
2c0a94c
added code and tests for tally.test and js
f583fd7
updated tests output for tally.test
93df342
added answers to invert.js and added a .test.js page to
6998347
Merge branch 'main' into coursework/sprint-2
JorvanW 5b96abc
removed code from sprint 1 and removed prep folder
f6cf1e1
removed file
fca3dde
removed errors in the lookup.js code and updated the test to function…
edb970d
removed console.log in code
d7af84e
updated tally.js and tally.test to turn and empty array into a empty …
37deb3c
removed excess comments in invert.js. fixed the code and added more …
bdcc0fc
updated answers for invert.js
04d19dd
removed unecessary comment
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,9 @@ | ||
| function contains() {} | ||
| function contains(object, property) { | ||
| if (Array.isArray(object)) { | ||
| throw new Error("Invalid parameter"); | ||
| } | ||
|
|
||
| return property in object; | ||
| } | ||
|
|
||
| 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,11 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(countryCurrencyPairs) { | ||
| const lookup = {}; | ||
|
|
||
| countryCurrencyPairs.forEach((pair) => { | ||
| lookup[pair[0]] = pair[1]; | ||
| }); | ||
|
|
||
| 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(array) { | ||
| if (!Array.isArray(array)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| if (array.length === 0) { | ||
| return {}; | ||
| } | ||
|
|
||
| const result = {}; | ||
|
|
||
| for (const item of array) { | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,22 +8,29 @@ | |
|
|
||
| function invert(obj) { | ||
| const invertedObj = {}; | ||
|
|
||
| for (const [key, value] of Object.entries(obj)) { | ||
| invertedObj.key = value; | ||
| invertedObj[value] = key; | ||
| } | ||
|
|
||
| return invertedObj; | ||
| } | ||
|
|
||
| // a) What is the current return value when invert is called with { a : 1 } | ||
| // { key: 1 } | ||
|
|
||
| // b) What is the current return value when invert is called with { a: 1, b: 2 } | ||
| // { key: 2 } | ||
|
|
||
| // c) What is the target return value when invert is called with {a : 1, b: 2} | ||
| // {"1": "a", "2":"b"} | ||
|
|
||
| // c) What does Object.entries return? Why is it needed in this program? | ||
| // Object Entries return an array of key value pairs and it's needed so the for...of loop goes through each key and value individually | ||
|
|
||
| // d) Explain why the current return value is different from the target output | ||
| // The current return value only shows {key: 2}. It doesn't show the first key and value only the second, | ||
| // and it doesn't specify the second key. Its just defined as 'key'. It also doesn't swap the key and value around as intended | ||
|
|
||
| // e) Fix the implementation of invert (and write tests to prove it's fixed!) | ||
|
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. This part is missing - your current test suite doesn't correctly test the behaviour of invert - check the example given in the top comment above again. You also haven't built the test suite up - start with a small example and build up to a bigger object. Please amend |
||
|
|
||
| module.exports = invert; | ||
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,13 @@ | ||
| const invert = require("./invert.js"); | ||
|
|
||
| test("when passed invert swaps single key-value pair", () => { | ||
| expect(invert({ a: 1 })).toEqual({ "1": "a" }); | ||
| }); | ||
|
|
||
| test("When invert is passed, multiple keys and values in the object should be swapped ", () => { | ||
| expect(invert({ x: 10, y: 20 })).toEqual({ "10": "x", "20": "y" }) | ||
| }); | ||
|
|
||
| test("when passed invert swaps string values", () => { | ||
| expect(invert({ first: "hello",second: "world" })).toEqual({ hello: "first", world: "second" }); | ||
| }); |
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.
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.
Nice logic here