-
-
Notifications
You must be signed in to change notification settings - Fork 155
London | 25-ITP-May | Hendrine Zeraua | Sprint 2| Data Groups #690
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 all commits
83d6713
6987734
24fd8fe
312832e
04340a2
ebe7623
24ff54e
5fc972f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
// Predict and explain first... | ||
|
||
bruschetta serves 2 | ||
ingredients: | ||
[object Object] | ||
|
||
// The first part, ${recipe.title} serves ${recipe.serves}, works fine because it's using string | ||
// and number values. But the last part, ${recipe}, tries to print the whole recipe object. | ||
// In JavaScript, when you put an object inside a string like that, it turns into [object Object]. | ||
// That's why you see that instead of the actual list of ingredients. | ||
|
||
|
||
// This program should log out the title, how many it serves and the ingredients. | ||
// Each ingredient should be logged on a new line | ||
// How can you fix it? | ||
// To fix it, we should print the ingredients properly. Since ingredients is an array, | ||
// we can join the items with \n so each one appears on a new line. | ||
|
||
const recipe = { | ||
title: "bruschetta", | ||
serves: 2, | ||
ingredients: ["olive oil", "tomatoes", "salt", "pepper"], | ||
}; | ||
|
||
// console.log(`${recipe.title} serves ${recipe.serves} | ||
// ingredients: | ||
// ${recipe}`); | ||
|
||
|
||
// Here's the fixed code: | ||
console.log(`${recipe.title} serves ${recipe.serves} | ||
ingredients: | ||
${recipe}`); | ||
${recipe.ingredients.join('\n')}`); | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
function contains() {} | ||
|
||
module.exports = contains; | ||
function contains(obj, key) { | ||
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) { | ||
return false; // invalid input — not a plain object | ||
} | ||
|
||
return Object.prototype.hasOwnProperty.call(obj, key); | ||
} | ||
|
||
module.exports = contains; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function createLookup() { | ||
// implementation here | ||
function createLookup(pairs) { | ||
const lookup = {}; | ||
|
||
for (const [country, currency] of pairs) { | ||
lookup[country] = currency; | ||
} | ||
|
||
return lookup; | ||
} | ||
|
||
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. 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" }? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
function tally() {} | ||
|
||
module.exports = tally; | ||
function tally(items) { | ||
if (!Array.isArray(items)) { | ||
throw new Error("Input must be an array"); | ||
} | ||
|
||
const counts = {}; | ||
|
||
for (const item of items) { | ||
counts[item] = (counts[item] || 0) + 1; | ||
} | ||
|
||
return counts; | ||
} | ||
|
||
module.exports = tally; | ||
|
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.
Does join change the type of values of recipe ingredients?