generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 209
London | ITP-MAY-25 | Surafel Workneh| Module: Data Groups | Sprint-2 #684
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
26 commits
Select commit
Hold shift + click to select a range
b8050db
update: fic code to call address is an object sprint-2 address.js
SuWebOnes a79f207
update: fix code using Object.values() for sprint-2 author.js
SuWebOnes 64b231f
update: fix code to list in ingredients inside object ingredients lis…
SuWebOnes 614a708
add json file
SuWebOnes 3cea226
changing json file
SuWebOnes 06df2e3
test for Normal input of multiple country-currency pairs
SuWebOnes d48e6ae
editing spell
SuWebOnes 76f4f9e
update: test array input
SuWebOnes c231d71
Duplicate country codes of last value wins
SuWebOnes 9667024
update code function for lockup
SuWebOnes 256f4bf
update: fix code for an edge case the implementation sprint-2/impleme…
SuWebOnes 7c609f1
update: testing other edge cases such as URL-encoded characters, Key…
SuWebOnes 60de1a2
update: fix test tally on an empty array returns an empty object tall…
SuWebOnes de11b52
update: test for return counts for each unique item tally.js
SuWebOnes ea4f6b0
update: test for invalid input tally.test.js
SuWebOnes ba34de6
update: fix function code for tally based on the test requirements ta…
SuWebOnes e971976
update: explain cases for original code for sprit-2 implementation in…
SuWebOnes e7dab95
update: fix code for sprit-2 implementation invert.js
SuWebOnes 7295458
update: include .export line
SuWebOnes a9a6722
update: Test invert for case empty object returns empty object in sp…
SuWebOnes 33f971e
update: Test invert for case inverts a single key-value pair in spri…
SuWebOnes fcb6576
update: Test invert for case inverts multiple key-value pairs in spr…
SuWebOnes 3d8ba46
update: Test: duplicate values in sprint-2 interpret invert.test.js
SuWebOnes e63ca77
update: Test invalid values in sprint-2 interpret invert.test.js
SuWebOnes 342794e
update: function including for valid and and invalid inputs in sprint…
SuWebOnes 7a2d94d
sytx in en-us in sprint-2 branch
SuWebOnes 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, key) { | ||
| if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { | ||
| return false; | ||
| } | ||
| return obj.hasOwnProperty(key); | ||
| } | ||
|
|
||
| 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,35 +1,37 @@ | ||
| const contains = require("./contains.js"); | ||
|
|
||
| /* | ||
| Implement a function called contains that checks an object contains a | ||
| particular property | ||
|
|
||
| E.g. contains({a: 1, b: 2}, 'a') // returns true | ||
| as the object contains a key of 'a' | ||
|
|
||
| E.g. contains({a: 1, b: 2}, 'c') // returns false | ||
| as the object doesn't contains a key of 'c' | ||
| */ | ||
|
|
||
| // Acceptance criteria: | ||
|
|
||
| // 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 | ||
|
|
||
| // Given an empty object | ||
| // When passed to contains | ||
| // Then it should return false | ||
| test.todo("contains on empty object returns false"); | ||
| test("contains on empty object returns false", () => { | ||
| expect(contains({}, "key")).toBe(false); | ||
| }); | ||
|
|
||
| // Given an object with properties | ||
| // When passed to contains with an existing property name | ||
| // Then it should return true | ||
| test("returns true for existing property", () => { | ||
| expect(contains({ name: "Alice", age: 30 }, "name")).toBe(true); | ||
| }); | ||
|
|
||
| // Given an object with properties | ||
| // When passed to contains with a non-existent property name | ||
| // Then it should return false | ||
| test("returns false for non-existent property", () => { | ||
| expect(contains({ name: "Alice", age: 30 }, "email")).toBe(false); | ||
| }); | ||
|
|
||
| // Given invalid parameters like an array | ||
| // When passed to contains | ||
| // Then it should return false or throw an error | ||
| test("returns false for array instead of object", () => { | ||
| expect(contains(["a", "b", "c"], "a")).toBe(false); | ||
| }); | ||
|
|
||
| test("returns false for null input", () => { | ||
| expect(contains(null, "key")).toBe(false); | ||
| }); | ||
|
|
||
| test("returns false for undefined input", () => { | ||
| expect(contains(undefined, "key")).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(pairs) { | ||
| const result = {}; | ||
| for (const [country, currency] of pairs) { | ||
| result[country] = currency; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| 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,15 @@ | ||
| function tally() {} | ||
| function tally(arr) { | ||
| if (!Array.isArray(arr)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| const counts = {}; | ||
|
|
||
| for (const item of arr) { | ||
| 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
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,24 @@ | ||
| const invert = require("./invert.js"); | ||
|
|
||
| // Test: empty object returns empty object | ||
| test("returns empty object when given an empty object", () => { | ||
| expect(invert({})).toEqual({}); | ||
| }); | ||
| // Test: single key-value pair | ||
| test("inverts a single key-value pair", () => { | ||
| expect(invert({ a: 1 })).toEqual({ 1: "a" }); | ||
| }); | ||
|
|
||
| // Test: multiple key-value pairs | ||
| test("inverts multiple key-value pairs", () => { | ||
| expect(invert({ a: 1, b: 2 })).toEqual({ 1: "a", 2: "b" }); | ||
| }); | ||
|
|
||
| // Test: duplicate values (last one wins) | ||
| test("overwrites key if values are not unique", () => { | ||
| expect(invert({ a: 1, b: 1 })).toEqual({ 1: "b" }); // 'b' overwrites 'a' | ||
| }); | ||
|
|
||
| test("throws error if input is not an object", () => { | ||
| expect(() => invert("string")).toThrow("Input must be a non-null object"); | ||
| }); |
Oops, something went wrong.
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.
Can you explain what decodeURIComponent method does?
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.
It converts URL-encoded characters back into their original form