generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 151
London | May-2025 | Ikenna Agulobi | Data Groups | sprint-2 #642
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
ike-agu
wants to merge
25
commits into
CodeYourFuture:main
Choose a base branch
from
ike-agu:datagroup-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
25 commits
Select commit
Hold shift + click to select a range
dd81331
Stop tracking prep-for-data-groups-module folder
ike-agu 0b1ba9a
Stop tracking prep-for-data-groups-module folder
ike-agu 2a5622c
Add prep-for-data-groups-module to .gitignore
ike-agu d139960
Update .gitignore to ignore prep-for-data-groups-module folder
ike-agu bd94341
fixed address object
ike-agu 4404e06
fixed the author object in author.js
ike-agu 4e6e1fd
fixed the recipe object in recipe.js
ike-agu 99926ba
implemented contains function and test cases to return true if obvjec…
ike-agu 83f6a17
fixed contains function to throw an error if invalid parameters are p…
ike-agu 7e8f294
added descriptive comments for future reference
ike-agu 9e7e414
created a create look up function and a test case multiple country co…
ike-agu b4ae8c6
added test case to return empty object if emty array is given
ike-agu 8259a3d
added descriptive comment for my future reference
ike-agu 60c733a
fixed parseQueryString function to work as expected and pass first test
ike-agu 8cc240c
fixed parse query function to throw new error for type of query strin…
ike-agu 7b8a20b
Implemented tally function and completed test cases
ike-agu f3943f1
Added comments to my code for my future reference
ike-agu 117b5c0
fixed the invert function to work as expected. Made comments to answe…
ike-agu 2b8644e
added test for function to return the inverted object
ike-agu 8f9a3f1
fixed the invert function to throw error incase the input is invalid.…
ike-agu f52d229
added test case to valid when invaklid inputs are passed to contains
ike-agu 7da2d46
fixed function to remove redundant if statement and deleted console.log
ike-agu a9e5c3c
fixed quesryString function to decode a URI component
ike-agu 4e3cbfa
adde inline comment for better understanding
ike-agu 31245ad
fixed tally function to return an object containing the count for eac…
ike-agu 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules | |
.vscode | ||
**/.DS_Store | ||
.idea | ||
prep-for-data-groups-module/ |
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 contains() {} | ||
function contains(obj, property) { | ||
//return false or throw error if parameters are invalid | ||
if (typeof obj !== "object" || Array.isArray(obj) || obj === null) { | ||
return false; | ||
} | ||
//check that the obj contains a property, and the property is not inherited. | ||
//N:B Object.hasOwn() strictly check for own properties and not inherited ones. | ||
if (Object.hasOwn(obj, property)) { | ||
return true; | ||
} else { | ||
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,11 @@ | ||
function createLookup() { | ||
// implementation here | ||
function createLookup(countryCodes) { | ||
const countryCodeAndCurrency = {}; | ||
//Iterating over the array to access the inner arrays | ||
for(const item of countryCodes){ | ||
countryCodeAndCurrency[item[0]] = item[1] | ||
} | ||
return countryCodeAndCurrency; | ||
} | ||
console.log(createLookup([["US", "USD"],["CA", "CAD"]])); | ||
|
||
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,32 @@ | ||
function tally() {} | ||
|
||
function tally(list) { | ||
const countItem = {}; | ||
//Throw new error if type is not array | ||
if (!Array.isArray(list)) { | ||
throw new Error("Your input is invalid!"); | ||
} | ||
//return empty object if array is empty | ||
if(list.length === 0){ | ||
return {} | ||
} | ||
//Loop through the array and count how many times each item occurs. | ||
for (let i = 0; i < list.length; i++) { | ||
let currentItem = list[i]; | ||
//if the current item exist, increment its count by 1. | ||
if (countItem[currentItem]) { | ||
countItem[currentItem] ++; | ||
} else { | ||
//Otherwise initial its count by 1 | ||
countItem[currentItem] = 1; | ||
} | ||
} | ||
return countItem; | ||
} | ||
// let call1 = tally(""); | ||
// let call2 = tally(["a", "a", "b", "a","c"]); | ||
// let call3 = tally(["a", "a", "a", "b", "z", "z"]); | ||
// let call4 = tally(["a", "a"]); | ||
// // console.log(call1); | ||
// // console.log(call2); | ||
// // console.log(call3); | ||
// // console.log(call4); | ||
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") | ||
const invert = require("./invert.js"); | ||
|
||
|
||
//Given a function invert | ||
// When passed an object and a property name | ||
// Then it should return the inverted object | ||
test("", () => { | ||
expect(invert({ a: 1 })).toEqual({ '1': 'a' }); | ||
}); | ||
|
||
// Given an empty object | ||
// When passed to invert | ||
// Then it should return an empty object | ||
test("When passed an empty object to invert, should return an empty object", () => { | ||
expect(invert({})).toEqual({}); | ||
}); | ||
|
||
// Given an invalid input, | ||
// When passed to invert | ||
// Then it should throw an error | ||
test("When invalid input, throw an error ", () => { | ||
expect(() => invert("")).toThrow("Your input is invalid!"); | ||
}); |
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.
Good job!
In the real world, URLs are usually encoded with percent encoding to represent special characters. In URL, & can be used as a separator (key=value&key=value...) or special character within a key or value. if we were to use & as a special character, we need to encode it.
Can you refactor the code so that parseQueryString("a%25b=c%26d") results in { "a%b": "c&d" }?
FYI, %25 is same as %, %26 is same as &
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've refactored my code as you requested.
parseQueryString("a%25b=c%26d") now correctly returns { "a%b": "c&d" }, and the function can now decode any other URI components as well. Thanks for your review and feedback.