Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 326
London | 26-ITP-May | Mandip Sanger | Sprint 2 | Coursework#1432
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?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4f497f8749a6a380c1f332385a98e18e861e8e1de036fd6658730b630357dec95043f8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,19 @@ | ||
| function contains() {} | ||
| function contains(object, property) { | ||
| if (object === null || typeof object !== "object" || Array.isArray(object)) { | ||
| return false; | ||
| } | ||
| return object.hasOwnProperty(property); | ||
| } | ||
| module.exports = contains; | ||
| // Implement a function called contains that checks an object contains a | ||
| // particular property | ||
| // E.g. contains({a: 1, b: 2}, 'a') // returns true | ||
| // as the object contains a key of 'a' | ||
| // E.g. contains({a: 1, b: 2}, 'c') // returns false | ||
| // as the object doesn't contains a key of 'c' | ||
| // */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,31 @@ | ||
| function parseQueryString(queryString) { | ||
| const queryParams = {}; | ||
| if (queryString === "") { | ||
| return queryString; | ||
| } | ||
| if (queryString.length === 0) { | ||
| return queryParams; | ||
| } | ||
Comment on lines
+3
to
8
Contributor 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. One of the if statements seems unnecessary. | ||
| const keyValuePairs = queryString.split("&"); | ||
| const keyValuePairs = queryString.split("&").filter((pair) => pair !== ""); | ||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| const indexFirstEqual = pair.indexOf("="); | ||
| let key; | ||
| let value; | ||
| if (indexFirstEqual === -1) { | ||
| key = pair; | ||
| value = ""; | ||
| } else { | ||
| key = pair.slice(0, indexFirstEqual); | ||
| value = pair.slice(indexFirstEqual + 1); | ||
| } | ||
| key = decodeURIComponent(key.replace(/\+/g, " ")); | ||
| value = decodeURIComponent(value.replace(/\+/g, " ")); | ||
| queryParams[key] = value; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,37 @@ | ||
| function tally() {} | ||
| function tally(array) { | ||
| const charCount = {}; | ||
Comment on lines
+1
to
+2
Contributor 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. Does the following function call returns the value you expect? Suggestion:
| ||
| if (!Array.isArray(array)) { | ||
| throw new Error(); | ||
| } | ||
| if (array.length === 0) { | ||
| return charCount; | ||
| } | ||
| for (const char of array) { | ||
| if (charCount[char]) { | ||
| charCount[char]++; | ||
| } else { | ||
| charCount[char] = 1; | ||
| } | ||
| } | ||
| return charCount; | ||
| } | ||
| module.exports = tally; | ||
| /** | ||
| * tally array | ||
| * | ||
| * In this task, you'll need to implement a function called tally | ||
| * that will take a list of items and count the frequency of each item | ||
| * in an array | ||
| * | ||
| * For example: | ||
| * | ||
| * tally(['a']), target output: { a: 1 } | ||
| * tally(['a', 'a', 'a']), target output: { a: 3 } | ||
| * tally(['a', 'a', 'b', 'c']), target output: { a : 2, b: 1, c: 1 } | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| const invert = require("./invert.js"); | ||
| test("should invert an object", () => { | ||
| expect(invert({ a: 1, b: 2 })).toEqual({ | ||
| 1: "a", | ||
| 2: "b", | ||
| }); | ||
| }); | ||
| test("should invert an object with one property", () => { | ||
| expect(invert({ a: 1 })).toEqual({ | ||
| 1: "a", | ||
| }); | ||
| }); | ||
| test("should return an empty object", () => { | ||
| expect(invert({})).toEqual({}); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 requirement is to output each ingredient on a new line.