-
-
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
Open
mandipsanger
wants to merge
14
commits into
CodeYourFuture:main
Choose a base branch
from
mandipsanger:sprint-2
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4f497f8
fix address
mandipsanger 749a6a3
author debug
mandipsanger 80c1f33
debug.recepie
mandipsanger 2385a98
implement contains
mandipsanger e18e861
implement contains
mandipsanger e8e1de0
too many errors replacing original
mandipsanger 36fd665
tally test
mandipsanger 8730b63
fix errors
mandipsanger 0357dec
invert test and implement
mandipsanger 95043f8
writing tests
mandipsanger 2bd72b8
Merge branch 'main' into sprint-2
mandipsanger 97a65d0
Refactor query string tests for clarity and correctness
mandipsanger a8fa96f
accept incoming changes of contains.js and tally.test.js
mandipsanger 29c92a5
recent changes to sprint 2
mandipsanger 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(object, property) { | ||
| if (typeof object !== "object" || object === null || Array.isArray(object)) { | ||
| throw new Error("contains requires an object"); | ||
| } | ||
|
|
||
| return Object.prototype.hasOwnProperty.call(object, 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' | ||
| // */ |
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,40 +1,74 @@ | ||
| const contains = require("./contains.js"); | ||
|
|
||
| /* | ||
| 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' | ||
|
|
||
| E.g. contains([1, 2, 3], 'a') throws Error("contains requires an object") | ||
| as an array isn't an object | ||
| */ | ||
|
|
||
| // Acceptance criteria: | ||
|
|
||
| // Given a contains function | ||
| // When passed an object and a property name | ||
| // Then it should return true if the object contains the property, false otherwise | ||
|
|
||
| // Given an empty object | ||
| // When passed to contains | ||
| // Then it should return false | ||
| test.todo("contains on empty object returns false"); | ||
| test("returns false for an empty object", () => { | ||
| const currentOutput = contains({}); | ||
| const targetOutput = false; | ||
|
|
||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an object with properties | ||
| // When passed to contains with an existing property name | ||
| // Then it should return true | ||
| test("returns true when the property exists", () => { | ||
| const currentOutput = contains({ a: 1, b: 2 }, "a"); | ||
| const targetOutput = true; | ||
|
|
||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an object with properties | ||
| // When passed to contains with a non-existent property name | ||
| // Then it should return false | ||
| test("returns false when the property does not exist", () => { | ||
| const currentOutput = contains({ a: 1, b: 2 }, "c"); | ||
| const targetOutput = false; | ||
|
|
||
| expect(currentOutput).toEqual(targetOutput); | ||
| }); | ||
|
|
||
| // Given an array | ||
| // When passed to contains | ||
| // Then it should throw an error | ||
| test("throws an error when passed an array", () => { | ||
| expect(() => contains([1, 2, 3], "a")).toThrow( | ||
| new Error("contains requires an object") | ||
| ); | ||
| }); | ||
|
|
||
| // Given a string | ||
| // When passed to contains | ||
| // Then it should throw an error | ||
| test("throws an error when passed a string", () => { | ||
| expect(() => contains("hello", "a")).toThrow( | ||
| new Error("contains requires an object") | ||
| ); | ||
| }); | ||
|
|
||
| // Given a number | ||
| // When passed to contains | ||
| // Then it should throw an error | ||
| test("throws an error when passed a number", () => { | ||
| expect(() => contains(42, "a")).toThrow( | ||
| new Error("contains requires an object") | ||
| ); | ||
| }); | ||
|
|
||
| // Given null | ||
| // When passed to contains | ||
| // Then it should throw an error | ||
| test("throws an error when passed null", () => { | ||
| expect(() => contains(null, "a")).toThrow( | ||
| new Error("contains requires an object") | ||
| ); | ||
| }); | ||
|
|
||
| // Given a value that isn't an object - an array, a string, a number, | ||
| // null, or no argument at all | ||
| // Given no argument | ||
| // When passed to contains | ||
| // Then it should throw Error("contains requires an object") | ||
| // (careful: typeof [] and typeof null are both "object") | ||
| // Then it should throw an error | ||
| test("throws an error when passed no argument", () => { | ||
| expect(() => contains()).toThrow(new Error("contains requires an object")); | ||
| }); |
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,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; | ||
| } | ||
|
|
||
|
|
||
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,33 @@ | ||
| function tally() {} | ||
| function tally(list) { | ||
| if (!Array.isArray(list)) { | ||
| throw new Error("tally requires an array"); | ||
| } | ||
|
|
||
| const result = {}; | ||
|
|
||
| for (const item of list) { | ||
| if (result[item]) { | ||
| result[item]++; | ||
| } else { | ||
| result[item] = 1; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| 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 } | ||
| */ |
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
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 requirement is to output each ingredient on a new line.