Repository navigation
London | 26-ITP-Sept | Hugh Mills | Sprint 2 | Sprint 2 coursework #1518
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
653f018
4a888c9
809ccc7
b8b4cc0
fe145bf
3910437
69ec2cb
a1b225a
3ae2c2a
8231232
cfaf2b5
5a1735e
f411077
e0082d8
e07a535
781d48e
47dcb5d
0cd4ffe
7747e05
fdd63d0
ea97ab9
72da3ae
fc2ec59
ec001df
192ed35
3467946
8ee667e
0066a76
9a3ac64
80a82ec
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,5 +1,6 @@ | ||
| // Predict and explain first... | ||
|
|
||
| // it does not make a new line as just pressing enter wont work for that. | ||
| // I was wrong, ingredients is showing [object Object], as it wont log out a full object like this. | ||
|
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. In the original template, which expression was interpolated at the spot that produced To "like" or "dislike" this comment, please follow this link |
||
| // 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? | ||
|
|
@@ -12,4 +13,4 @@ const recipe = { | |
|
|
||
| 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,8 @@ | ||
| function contains() {} | ||
| function contains(object, property) { | ||
| if (Array.isArray(object)) { | ||
| throw new Error("contains requires an object"); | ||
| } | ||
| return property in object; | ||
|
Comment on lines
+2
to
+5
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. The stated invalid inputs also include strings, numbers, To "like" or "dislike" this comment, please follow this link |
||
| } | ||
|
|
||
| module.exports = contains; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(countryCurrencyPairs) { | ||
| const lookup = Object.fromEntries(countryCurrencyPairs); | ||
| return lookup; | ||
| } | ||
|
|
||
| module.exports = createLookup; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,13 @@ function parseQueryString(queryString) { | |
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| if (pair === "") { | ||
| continue; | ||
| } | ||
| const parts = pair.split("="); | ||
|
|
||
| const key = decodeURIComponent(parts[0]); | ||
| const value = decodeURIComponent(parts.slice(1).join("=")); | ||
|
Comment on lines
+14
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. What key and value does this parsing produce for the existing To "like" or "dislike" this comment, please follow this link |
||
| queryParams[key] = value; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,17 @@ | ||
| function tally() {} | ||
| function tally(array) { | ||
| const lookup = {}; | ||
| if (!Array.isArray(array)) { | ||
| throw new Error("tally requires an array"); | ||
| } | ||
|
|
||
| for (const item of array) { | ||
| if (lookup[item]) { | ||
| lookup[item] += 1; | ||
| } else { | ||
| lookup[item] = 1; | ||
| } | ||
| } | ||
| return lookup; | ||
| } | ||
|
|
||
| module.exports = tally; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| const invert = require("./invert.js"); | ||
|
|
||
| // inverting original input | ||
| test("Inverting original input of 1 property", () => { | ||
| expect(invert({ a: 1 })).toEqual({ 1: "a" }); | ||
| }); | ||
|
|
||
| // inverting original input of 2 objects and 2 properties | ||
| test("Inverting original input of 2 properties", () => { | ||
| expect(invert({ a: 1, b: 2 })).toEqual({ 1: "a", 2: "b" }); | ||
| }); | ||
|
|
||
| // inverting an empty object | ||
| test("Inverting original input correctly", () => { | ||
| expect(invert({})).toEqual({}); | ||
| }); | ||
|
|
||
| // Inverting an object with an empty string as a value | ||
| test("Inverting an object with an empty string as a value", () => { | ||
| expect(invert({ a: "" })).toEqual({ "": "a" }); | ||
| }); | ||
|
|
||
| // Inverting an object with an empty string as a key | ||
| test("Inverting an object with an empty string as a key", () => { | ||
| expect(invert({ "": 1 })).toEqual({ 1: "" }); | ||
| }); | ||
|
|
||
| // Inverting an object with multiple properties sharing the same value | ||
| test("Inverting an object with multiple properties sharing the same value", () => { | ||
| expect(invert({ a: 2, b: 2, c: 2 })).toEqual({ 2: "a", 2: "b", 2: "c" }); | ||
| }); |
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.
When the loop starts with the plain
authorobject, does it ever assign a value tovalue?To "like" or "dislike" this comment, please follow this link