-
-
Notifications
You must be signed in to change notification settings - Fork 327
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
10
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
10 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 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 (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' | ||
| // */ |
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,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,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 } | ||
| */ | ||
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 |
|---|---|---|
| @@ -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({}); | ||
| }); |
Oops, something went wrong.
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.