-
-
Notifications
You must be signed in to change notification settings - Fork 147
West Midlands | ITP-MAY25 | Saleh Yousef | Module-Data-Groups | Sprint-2 #622
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. Correct |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Predict and explain first... | ||
// Predict and explain first... it won't work because the ingredients are not being accessed correctly. | ||
|
||
// This program should log out the title, how many it serves and the ingredients. | ||
// Each ingredient should be logged on a new line | ||
|
@@ -11,5 +11,7 @@ const recipe = { | |
}; | ||
|
||
console.log(`${recipe.title} serves ${recipe.serves} | ||
ingredients: | ||
${recipe}`); | ||
ingredients:`); | ||
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. Minor query here shouldn't the console read out "bruschetta serves 2, the ingredients are: ". Your code reads "bruschetta serves 2 ingredients: ". Otherwise this works |
||
recipe.ingredients.forEach((ingredient) => { | ||
console.log(ingredient); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
function contains() {} | ||
function contains(obj, key) { | ||
if (typeof obj !== "object" || obj === null || Array.isArray(obj)) { | ||
return false; | ||
} | ||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
|
||
} | ||
|
||
module.exports = contains; |
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. tests passed |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function createLookup() { | ||
// implementation here | ||
function createLookup(pairs) { | ||
const result = {}; | ||
|
||
for (const [countryCode, currencyCode] of pairs) { | ||
result[countryCode] = currencyCode; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
module.exports = createLookup; |
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. Tests passed |
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. code works however do some further research on how this could be improved. For example dealing with URL encoded string(decodeURIComponent). Then you could write a test to see if your solution works. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ function parseQueryString(queryString) { | |
const keyValuePairs = queryString.split("&"); | ||
|
||
for (const pair of keyValuePairs) { | ||
const [key, value] = pair.split("="); | ||
queryParams[key] = value; | ||
const [key, ...rest] = pair.split("="); | ||
queryParams[key] = rest.join("="); | ||
Comment on lines
+9
to
+10
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. It looks like you fixed a bug here but didn't write a test for it - can you add a test for the edge case you fixed? |
||
} | ||
|
||
return queryParams; | ||
|
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. test passed |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,21 @@ test("parses querystring values containing =", () => { | |
"equation": "x=y+1", | ||
}); | ||
}); | ||
|
||
test("parses querystring with multiple values", () => { | ||
expect(parseQueryString("name=John&age=30")).toEqual({ | ||
"name": "John", | ||
"age": "30", | ||
}); | ||
}); | ||
test("parses querystring with multiple values with same key", () => { | ||
expect(parseQueryString("name=John&name=Jane")).toEqual({ | ||
"name": "Jane", // Last value should overwrite previous ones | ||
}); | ||
}); | ||
|
||
test("parses querystring without key", () => { | ||
Comment on lines
+13
to
+26
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. Good edge cases! |
||
expect(parseQueryString("=Python")).toEqual({ | ||
"": "Python", // Empty key should be handled | ||
}); | ||
}); |
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. Code works for tests. Do some further research on how code could be improved to handle edge cases such as undefined values. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
function tally() {} | ||
function tally(array) { | ||
if (!Array.isArray(array)) { | ||
throw new Error("Input must be an array"); | ||
} | ||
const counts = {}; | ||
|
||
for (const item of array) { | ||
if (counts[item]) { | ||
counts[item] += 1; | ||
} else { | ||
counts[item] = 1; | ||
} | ||
} | ||
|
||
return counts; | ||
} | ||
|
||
module.exports = tally; |
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. tests passed |
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. Both tests pass - well done |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Correct