Repository navigation
Manchester | 26-ITP-Sep | Mathew Shaibu | Sprint 2 | Module data group sprint 2 #1499
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
MattCarolus10
wants to merge
60
commits into
CodeYourFuture:main
Choose a base branch
from
MattCarolus10:Module-data-group-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
60 commits
Select commit
Hold shift + click to select a range
8531191
object prep
MattCarolus10 037311d
fix houseNumber error
MattCarolus10 13f83e1
fix author object iteration
MattCarolus10 3d72ba1
add tests for parseQueryString function to validate query string parsing
MattCarolus10 454659b
add function to double all numbers in an array
MattCarolus10 af702ab
fix formatting in address.js comments for clarity
MattCarolus10 e6ed80a
fix recipe logging to display ingredients correctly
MattCarolus10 e80fd6f
fix comments in recipe.js to clarify logging functionality
MattCarolus10 74c65b7
implement test for contains function to check empty object case
MattCarolus10 c61f58e
implement contains function to check if property exists in object
MattCarolus10 438293b
refactor contains.test.js to improve test structure and formatting
MattCarolus10 4e217bc
add test for contains function to verify behavior with missing property
MattCarolus10 b72528b
add test to ensure contains function throws error for array input
MattCarolus10 e8cf923
refactor contains function to validate input type before checking pro…
MattCarolus10 8e89f1d
remove redundant comments and acceptance criteria from contains.test.js
MattCarolus10 c39280d
implement test for createLookup function to validate country-currency…
MattCarolus10 80034ab
fix: update test to validate correct output for createLookup function
MattCarolus10 8c1878d
implement createLookup function to map country-currency pairs
MattCarolus10 62d2398
refactor: improve formatting of createLookup test and remove redundan…
MattCarolus10 b1fdc4d
refactor: simplify parseQueryString function by removing redundant ch…
MattCarolus10 05ccd8c
refactor: clean up parseQueryString function by removing unnecessary …
MattCarolus10 fe222e0
fix: correct value assignment in parseQueryString and decode URI comp…
MattCarolus10 89d8fda
fix: decode URI components in parseQueryString function
MattCarolus10 17adfe9
fix: decode URI components in parseQueryString function
MattCarolus10 4918e85
refactor: improve key and value decoding in parseQueryString function
MattCarolus10 f573273
test: add test for handling empty query string
MattCarolus10 05ee028
test: add test for handling values with both + and percent-encoding
MattCarolus10 15fe829
test: implement test for tally function with an empty array
MattCarolus10 8eb4f2d
test: fix indentation in tally test cases
MattCarolus10 967cdf6
test: add assertion for counting unique items in tally function
MattCarolus10 1492450
test: add tests for handling invalid input in tally function
MattCarolus10 d2fb260
refactor: remove unnecessary comments and documentation from tally te…
MattCarolus10 77dc8de
feat: implement tally function to count occurrences in an array
MattCarolus10 5cb05ee
fix: correct condition to check if input is an array in tally function
MattCarolus10 ef80285
fix: correct implementation of invert function to properly swap keys …
MattCarolus10 d2795ff
fix: update module export for invert function
MattCarolus10 6eff4d9
fix: update comments in invert function to clarify expected behavior …
MattCarolus10 ad4efb5
test: add unit test for invert function to verify key-value swapping
MattCarolus10 e18c645
fix: add missing newline and correct syntax in invert test cases
MattCarolus10 3deb65c
fix: correct formatting and add missing newline in invert test cases
MattCarolus10 8ad6494
test: add unit test for handling empty object in invert function
MattCarolus10 4476d4a
fix: correct expected output for key-value swapping test case
MattCarolus10 5ab6b3e
Remove prep files from sprint branch
MattCarolus10 2a43c8c
fix: update comment for clarity on ingredient printing issue
MattCarolus10 5082a4d
test: add example usage for calculateMode function
MattCarolus10 fcdb3b7
test: add case for contains function to throw error on array input
MattCarolus10 c167eac
refactor: update test cases for contains function to improve clarity …
MattCarolus10 4335eb3
test: add case for contains function to throw error on null input
MattCarolus10 417ac1b
test: add case for contains function to throw error when no argument …
MattCarolus10 58d2351
refactor: remove commented-out test cases for clarity
MattCarolus10 5a54171
test: uncomment test cases for array and object handling in contains …
MattCarolus10 f6f9b2a
test: add test case for creating a lookup with a single currency pair
MattCarolus10 0a4fb24
test: add case to return an empty object for an empty array in create…
MattCarolus10 2343205
fix: format whitespace in test cases for consistency
MattCarolus10 0672819
fix: correct expected value for single currency pair lookup test
MattCarolus10 e9727d9
refactor: rename variables for clarity in parseQueryString function
MattCarolus10 745fa98
refactor: update tally tests for clarity and organization
MattCarolus10 2470fea
test: add case for counting occurrences of different letters in tally…
MattCarolus10 68b000d
test: enable test for tally on an empty array
MattCarolus10 3b5c96f
refactor: remove commented-out tests for clarity in tally test file
MattCarolus10 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(object, property) { | ||
| if (typeof object !== "object" || object === null || Array.isArray(object)) { | ||
| throw new Error("contains requires an object"); | ||
| } | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,33 @@ | ||
| const contains = require("./contains.js"); | ||
|
|
||
| /* | ||
| Implement a function called contains that checks an object contains a | ||
| particular property | ||
| test("contains throws for a string", () => { | ||
| expect(() => contains("hello", "a")).toThrow("contains requires an object"); | ||
| }); | ||
|
|
||
| E.g. contains({a: 1, b: 2}, 'a') // returns true | ||
| as the object contains a key of 'a' | ||
| test("contains throws for a number", () => { | ||
| expect(() => contains(42, "a")).toThrow("contains requires an object"); | ||
| }); | ||
|
|
||
| E.g. contains({a: 1, b: 2}, 'c') // returns false | ||
| as the object doesn't contains a key of 'c' | ||
| test("contains throws for null", () => { | ||
| expect(() => contains(null, "a")).toThrow("contains requires an object"); | ||
| }); | ||
|
|
||
| E.g. contains([1, 2, 3], 'a') throws Error("contains requires an object") | ||
| as an array isn't an object | ||
| */ | ||
| test("contains throws when no argument is passed", () => { | ||
| expect(() => contains()).toThrow("contains requires an object"); | ||
| }); | ||
|
|
||
| // Acceptance criteria: | ||
| test("contains throws for an array", () => { | ||
| expect(() => contains([1, 2, 3], "a")).toThrow("contains requires an object"); | ||
| }); | ||
|
|
||
| // Given a contains function | ||
| // When passed an object and a property name | ||
| // Then it should return true if the object contains the property, false otherwise | ||
| test("contains on empty object returns false", () => { | ||
| expect(contains({}, "a")).toBe(false); | ||
| }); | ||
|
|
||
| // Given an empty object | ||
| // When passed to contains | ||
| // Then it should return false | ||
| test.todo("contains on empty object returns false"); | ||
| test("contains an object with existing property, return true", () => { | ||
| expect(contains({ a: 1, b: 2 }, "a")).toBe(true); | ||
| }); | ||
|
|
||
| // Given an object with properties | ||
| // When passed to contains with an existing property name | ||
| // Then it should return true | ||
|
|
||
| // Given an object with properties | ||
| // When passed to contains with a non-existent property name | ||
| // Then it should return false | ||
|
|
||
| // Given a value that isn't an object - an array, a string, a number, | ||
| // null, or no argument at all | ||
| // When passed to contains | ||
| // Then it should throw Error("contains requires an object") | ||
| // (careful: typeof [] and typeof null are both "object") | ||
| test("contains an object with missing property, return false", () => { | ||
| expect(contains({ a: 1, b: 2 }, "c")).toBe(false); | ||
| }); |
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,9 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(countryCurrencyPairs) { | ||
| const lookup = {}; | ||
| for (const [country, currency] of countryCurrencyPairs) { | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,18 @@ | ||
| const createLookup = require("./lookup.js"); | ||
|
|
||
| test.todo("creates a country currency code lookup for multiple codes"); | ||
|
|
||
| /* | ||
|
|
||
| Create a lookup object of key value pairs from an array of code pairs | ||
|
|
||
| Acceptance Criteria: | ||
|
|
||
| Given | ||
| - An array of arrays representing country code and currency code pairs | ||
| e.g. [['US', 'USD'], ['CA', 'CAD']] | ||
|
|
||
| When | ||
| - createLookup function is called with the country-currency array as an argument | ||
|
|
||
| Then | ||
| - It should return an object where: | ||
| - The keys are the country codes | ||
| - The values are the corresponding currency codes | ||
|
|
||
| Example | ||
| Given: [['US', 'USD'], ['CA', 'CAD']] | ||
|
|
||
| When | ||
| createLookup(countryCurrencyPairs) is called | ||
|
|
||
| Then | ||
| It should return: | ||
| { | ||
| 'US': 'USD', | ||
| 'CA': 'CAD' | ||
| } | ||
| */ | ||
| test("creates a country currency code lookup for multiple codes", () => { | ||
| expect( | ||
| createLookup([ | ||
| ["US", "USD"], | ||
| ["CA", "CAD"], | ||
| ]) | ||
| ).toEqual({ US: "USD", CA: "CAD" }); | ||
| }); | ||
|
Liam310 marked this conversation as resolved.
Resolved
|
||
|
|
||
| test("creates a lookup for single pair", () => { | ||
| expect(createLookup([["US", "USD"]])).toEqual({ US: "USD" }); | ||
| }); | ||
|
|
||
| test("return an empty object for an empty array", () => { | ||
| expect(createLookup([])).toEqual({}); | ||
| }); | ||
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,14 @@ | ||
| function tally() {} | ||
| function tally(list) { | ||
| if (!Array.isArray(list)) { | ||
| throw new Error("tally requires an array"); | ||
| } | ||
|
|
||
| const counts = {}; | ||
|
|
||
| for (const item of list) { | ||
| counts[item] = (counts[item] || 0) + 1; | ||
| } | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,19 @@ | ||
| const tally = require("./tally.js"); | ||
|
|
||
| /** | ||
| * tally array | ||
| * | ||
| * In this task, you'll need to implement a function called tally | ||
| * that will take a list of items and count the frequency of each item | ||
| * in an array | ||
| * | ||
| * For example: | ||
| * | ||
| * tally(['a']), target output: { a: 1 } | ||
| * tally(['a', 'a', 'a']), target output: { a: 3 } | ||
| * tally(['a', 'a', 'b', 'c']), target output: { a : 2, b: 1, c: 1 } | ||
| */ | ||
| test("counts multiple occurrences of the same letter", () => { | ||
| expect(tally(["a", "a", "a"])).toEqual({a: 3}); | ||
| }); | ||
|
|
||
| // Acceptance criteria: | ||
| test("count occurrences of different letters", () => { | ||
| expect(tally(["a", "a", "b", "c"])).toEqual({a: 2, b: 1, c: 1}); | ||
| }); | ||
|
|
||
| // Given a function called tally | ||
| // When passed an array of items | ||
| // Then it should return an object containing the count for each unique item | ||
| test("tally on an empty array returns an empty object", () => { | ||
| expect(tally([])).toEqual({}); | ||
| }); | ||
|
|
||
| // Given an empty array | ||
| // When passed to tally | ||
| // Then it should return an empty object | ||
| test.todo("tally on an empty array returns an empty object"); | ||
|
|
||
| // Given an array with duplicate items | ||
| // When passed to tally | ||
| // Then it should return counts for each unique item | ||
|
|
||
| // Given an invalid input like a string, a number, or no argument at all | ||
| // When passed to tally | ||
| // Then it should throw Error("tally requires an array") | ||
| test("tally throws for invalid input", () => { | ||
| expect(() => tally("banana")).toThrow("tally requires an array"); | ||
| expect(() => tally(42)).toThrow("tally requires an array"); | ||
| expect(() => tally()).toThrow("tally requires an array"); | ||
| }); | ||
|
Liam310 marked this conversation as resolved.
Resolved
|
||
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,13 @@ | ||
| const invert = require("./invert.js"); | ||
|
|
||
| test("swaps key with values", () => { | ||
| expect(invert({ x: 10, y: 20 })).toEqual({ 10: "x", 20: "y" }); | ||
| }); | ||
|
|
||
| test("handles single entry", () => { | ||
| expect(invert({ a: 1 })).toEqual({ 1: "a" }); | ||
| }); | ||
|
|
||
| test("handles an empty object", () => { | ||
| expect(invert({})).toEqual({}); | ||
| }); | ||
|
Liam310 marked this conversation as resolved.
Resolved
|
||
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 |
|---|---|---|
|
|
@@ -46,4 +46,6 @@ function calculateMode(list) { | |
| return mode; | ||
| } | ||
|
|
||
| calculateMode([2,4,5,5,6]) | ||
|
|
||
| module.exports = calculateMode; | ||
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.