generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 201
Manchester | 25-ITP-Sep | Mahtem T. Mengstu | Sprint 2 |Sprint-2-courseWork #913
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
Mahtem
wants to merge
26
commits into
CodeYourFuture:main
Choose a base branch
from
Mahtem:Sprint-2-courseWork
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 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
13acaf4
Address.js log function corrected
Mahtem 7f8b224
Author.js corrected.
Mahtem ba4ef98
recipe.js log function corrected.
Mahtem 6453fe4
contains.js function implemented and tested.
Mahtem cb4642b
In contains.test.js tests for contains.test.js passed
Mahtem 9dd1769
In lookup.js function createLookup implemented.
Mahtem 8bdd6c5
In lookup.test.js test cases added and passed.
Mahtem 2c03056
In querystring.js function implemented.
Mahtem 1101ce6
In querystring.test.js test edge cases added.
Mahtem d0665bd
In tally.js function tally() implemented.
Mahtem d471bca
In tally.test.js test cases added and passed.
Mahtem e550d17
In invert.js invert function implemented.
Mahtem 218caa6
// In invert.test.js test cases tested.
Mahtem d2985e4
In count-words.js function countWords implemented.
Mahtem 6dff138
In mode.js function calculateMode refactored.
Mahtem 0088e75
In mode.test.js test cases passed
Mahtem bd20fa1
In till.js function implemented.
Mahtem 3735e91
In till.test.js test cases written and tested.
Mahtem 2f7f0e2
recipe.js modified "${recipe.ingredients.join("\n")}`) to make ingre…
Mahtem 161b871
In contains.js modified return function as return Object.hasOwn(obj, …
Mahtem 5cddc23
contains.test.js re-tested.
Mahtem aab642f
Decoding of paramKey = decodeURIComponent(pair); added.
Mahtem 7ef1f9c
In tally.js modification made.
Mahtem ba1bc62
Modified to handle inherent property cases and to remove empty spaces.
Mahtem 2528d55
The "if (typeof obj !== "object" || obj === null)" modified.
Mahtem 8e4807e
Test case description updated
Mahtem 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,19 @@ | ||
| function contains() {} | ||
| function contains(obj, key) { | ||
| if (typeof obj !== "object" || obj === null) { | ||
| return false; | ||
| } | ||
| //return key in obj; | ||
| return Object.hasOwn(obj, key); | ||
|
|
||
| } | ||
|
|
||
| module.exports = contains; | ||
|
|
||
| // In contains.js function implemented and tested. | ||
|
|
||
| let obj = {}, propertyName = "toString"; | ||
| console.log( propertyName in obj ); // true | ||
| console.log( Object.hasOwn(obj, propertyName) ); // false | ||
|
|
||
| // In contains.js modified return function as return Object.hasOwn(obj, key); | ||
| // The "if (typeof obj !== "object" || obj === null)" modified. |
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,27 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(input) { | ||
| if (!Array.isArray(input)) { | ||
| throw new Error("Input must be an array of [country, currency] pairs"); | ||
| } | ||
|
|
||
| const lookup = {}; | ||
|
|
||
| for (const pair of input) { | ||
| if (!Array.isArray(pair) || pair.length !== 2) { | ||
| throw new Error("Each item must be an array of [country, currency]"); | ||
| } | ||
|
|
||
| const [country, currency] = pair; | ||
|
|
||
| if (typeof country !== "string" || typeof currency !== "string") { | ||
| throw new Error("Each item must be an array of [country, currency]"); | ||
| } | ||
|
|
||
| lookup[country] = currency; | ||
| } | ||
|
|
||
| return lookup; | ||
| } | ||
|
|
||
| module.exports = createLookup; | ||
|
|
||
| // In lookup.js function createLookup implemented. |
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,16 +1,46 @@ | ||
| function parseQueryString(queryString) { | ||
| const queryParams = {}; | ||
| const parsedParams = {}; // Gets the final key-value pairs | ||
|
|
||
| if (!queryString) return parsedParams; | ||
|
|
||
| // Removes leading '?' if present | ||
|
|
||
| if (queryString.startsWith("?")) { | ||
| queryString = queryString.slice(1); | ||
| } | ||
|
|
||
| if (queryString.length === 0) { | ||
| return queryParams; | ||
| return parsedParams; | ||
| } | ||
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| queryParams[key] = value; | ||
| // Split the string into individual key-value pairs | ||
| const pairs = queryString.split("&"); | ||
|
|
||
| for (const pair of pairs) { | ||
| if (!pair) continue; // skip empty segments (like from && or trailing &) eg "name=John&&age=30" | ||
|
|
||
| const equalSignIndex = pair.indexOf("="); | ||
|
|
||
| let paramKey, paramValue; | ||
|
|
||
| if (equalSignIndex === -1) { | ||
|
|
||
| // If '=' not found we have a key exists but value is empty | ||
|
|
||
| paramKey = decodeURIComponent(pair); | ||
| paramValue = ""; | ||
| } else { | ||
| paramKey = decodeURIComponent(pair.slice(0, equalSignIndex)); | ||
| paramValue = decodeURIComponent(pair.slice(equalSignIndex + 1)); | ||
| } | ||
|
|
||
| parsedParams[paramKey] = paramValue; // overwrite previous value if key repeats | ||
| } | ||
|
|
||
| return queryParams; | ||
| return parsedParams; | ||
| } | ||
|
|
||
| module.exports = parseQueryString; | ||
|
|
||
| // In querystring.js function implemented. | ||
| // Decoding of paramKey = decodeURIComponent(pair); added. |
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,29 @@ | ||
| function tally() {} | ||
| function tally(items) { | ||
| if (!Array.isArray(items)) { | ||
| throw new Error("Input must be an array"); | ||
| } | ||
|
|
||
| if (items.length === 0) { | ||
| return {}; | ||
| } | ||
|
|
||
| const counts = Object.create(null); | ||
|
|
||
| for (const item of items) { | ||
|
|
||
| // Convert objects and arrays to JSON string | ||
| const key = (typeof item === "object" && item !== null) ? JSON.stringify(item) : item; | ||
| counts[key] = (counts[key] || 0) + 1; | ||
| } | ||
|
|
||
| return counts; | ||
| } | ||
|
|
||
| console.log(tally(["toStrin", "toStrin"])); | ||
| console.log(tally(["toString", "toString"])); | ||
|
|
||
| module.exports = tally; | ||
|
|
||
| // In tally.js function tally() implemented. | ||
|
|
||
| // modification made. |
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.
The test on line 56 does not quite match the test description.
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.
Yes, it's right.. I have tried to make is separated as follows:
test("Should correctly detect keys in arrays", () => {
expect(contains([1, 2, 3], "1")).toEqual(true); // "1" is a key
expect(contains([1, 2, 3], "3")).toEqual(false); // "3" is not a key
});
test("Should return false when invalid parameters are used", () => {
expect(contains(null, "a")).toEqual(false); // null
expect(contains(5, "a")).toEqual(false); // number
expect(contains("hello", "a")).toEqual(false); // string