generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 155
ZA-ITP-May-2025 | Christian Mayamba | Module-Data-Groups | Week 2 #699
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
c-mayamba
wants to merge
12
commits into
CodeYourFuture:main
Choose a base branch
from
c-mayamba:sprint2-exercises
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
8517889
address debug solved
c-mayamba dd1a25d
author debug solved
c-mayamba f7196ea
author debug iteration
c-mayamba 979713b
recipe debug done
c-mayamba 0de758b
contains implement passed
c-mayamba 71c113b
lookup implement passed
c-mayamba 60a6ee6
tally implement solved
c-mayamba be7a7aa
querystring implement passed
c-mayamba 81b68b6
interpret invert done
c-mayamba 15fa4b2
Merge branch 'CodeYourFuture:main' into sprint2-exercises
c-mayamba 3ee54c2
Review feedback changes
c-mayamba cf888ae
Merge branch 'sprint2-exercises' of https://github.com/c-mayamba/Modu…
c-mayamba 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,22 @@ | ||
function contains() {} | ||
function contains(object1, prop1) { | ||
if ( | ||
typeof object1 !== "object" || | ||
object1 === null || | ||
Array.isArray(object1) | ||
) { | ||
console.log("Error: object1 must be a non-null object and not an array."); | ||
return false; | ||
} | ||
|
||
if (prop1 in object1) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
const myObject = [15, 20, 30]; | ||
|
||
console.log(contains(myObject, "test2")); | ||
|
||
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,15 @@ | ||
function createLookup() { | ||
// implementation here | ||
function createLookup(nestedArray) { | ||
let finalObject = {}; | ||
|
||
nestedArray.forEach((pair) => { | ||
const key = pair[0]; | ||
const value = pair[1]; | ||
finalObject[key] = value; | ||
}); | ||
|
||
return finalObject; | ||
} | ||
|
||
console.log(createLookup([["NG", "Naira"]])); | ||
|
||
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,19 @@ | ||
function tally() {} | ||
function tally(array) { | ||
if (!Array.isArray(array)) { | ||
throw new Error("Input must be an array"); | ||
} | ||
|
||
const result = {}; | ||
|
||
for (const item of array) { | ||
if (result[item]) { | ||
result[item] = result[item] + 1; | ||
} else { | ||
result[item] = 1; | ||
} | ||
} | ||
|
||
Comment on lines
+8
to
+15
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. Well done! As a challenge, can you refactor the code with an array method and ternary operator so the code can be more simple and concise? |
||
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
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,21 @@ | ||
const objectInvert = require("./invert.js"); | ||
|
||
test("Inverting an object with one key and value", () => { | ||
const test1 = { a: 1 }; | ||
expect(objectInvert(test1)).toEqual({ 1: "a" }); | ||
}); | ||
|
||
test("Inverting an object with two keys and values", () => { | ||
const test2 = { a: 1, b: 2 }; | ||
expect(objectInvert(test2)).toEqual({ 1: "a", 2: "b" }); | ||
}); | ||
|
||
test("Inverting an empty object", () => { | ||
const test3 = {}; | ||
expect(objectInvert(test3)).toEqual({}); | ||
}); | ||
|
||
test("Inverting an object with duplicate values", () => { | ||
const test4 = { a: 1, b: 1, c: 2 }; | ||
expect(objectInvert(test4)).toEqual({ 1: "b", 2: "c" }); | ||
}); |
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 &