-
-
Notifications
You must be signed in to change notification settings - Fork 283
London |ITP-Jan-2016 | Ping Wang | Sprint 2 |Coursework #1023
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a5f25c7
commit
pathywang ca26a21
commit
pathywang b8b5c2c
commit
pathywang 3339f76
complete look up
pathywang d25f0a1
complete query
pathywang 4b2cca7
complete tally
pathywang 9fcea26
amend function
pathywang bac8a52
correction
pathywang a25d8cf
correction
pathywang 87488ee
correction
pathywang 587a287
correction
pathywang fe9dca5
test
pathywang 452cac7
syntax
pathywang 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,15 @@ | ||
| function contains() {} | ||
| function contains(object, property) { | ||
| if (typeof object !== 'object' || object === null || Array.isArray(object)) { | ||
| return false; | ||
| } | ||
| return object.hasOwnProperty(property); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| const object={name:'jin', age:13} | ||
|
|
||
| console.log (contains(object, 'age')) | ||
| console.log (contains(object, 'nice')) | ||
|
|
||
| module.exports = contains; |
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,5 +1,14 @@ | ||
| function createLookup() { | ||
| // implementation here | ||
| function createLookup(countryCurrencyPairs) { | ||
| const countryCodeCurrency = {} | ||
|
|
||
| for (const[country, currency] of countryCurrencyPairs) { | ||
| countryCodeCurrency[country] = currency | ||
| } | ||
|
|
||
| return countryCodeCurrency | ||
| } | ||
|
|
||
| console.log(createLookup([['GB', 'GBP']])); | ||
|
|
||
|
|
||
| module.exports = createLookup; | ||
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,16 +1,30 @@ | ||
| function parseQueryString(queryString) { | ||
| const queryParams = {}; | ||
| if (queryString.length === 0) { | ||
|
|
||
| if (typeof queryString!=="string"||queryString.length === 0) { | ||
| return queryParams; | ||
| } | ||
|
|
||
| const keyValuePairs = queryString.split("&"); | ||
|
|
||
| for (const pair of keyValuePairs) { | ||
| const [key, value] = pair.split("="); | ||
| if (!pair.includes("=")) continue; | ||
|
|
||
| const equalIndex = pair.indexOf("="); | ||
|
|
||
| const key = pair.slice(0, equalIndex); | ||
| const value = pair.slice(equalIndex + 1); | ||
|
|
||
| if (key === "") continue; | ||
|
|
||
| queryParams[key] = value; | ||
| } | ||
|
|
||
| return queryParams; | ||
| } | ||
|
|
||
| console.log(parseQueryString("color=blue&quality=good")) | ||
| console.log(parseQueryString("equation=x=y+1")) | ||
| console.log(parseQueryString("")) | ||
|
cjyuan marked this conversation as resolved.
|
||
|
|
||
| module.exports = parseQueryString; | ||
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,28 @@ | ||
| function tally() {} | ||
| function tally(array) { | ||
| if (!Array.isArray(array)) { | ||
| throw new Error("Invalid input: expected an array"); | ||
| } | ||
|
|
||
| const count = Object.create(null); | ||
|
|
||
| for (const item of array) { | ||
| if (count[item]) { | ||
| count[item] += 1; | ||
| } else { | ||
| count[item] = 1; | ||
| } | ||
| } | ||
|
|
||
| return count; | ||
| } | ||
|
|
||
| console.log(tally([ 2,"bee",2,"apple","apple",2, "banana"])) | ||
|
|
||
| try { | ||
| console.log(tally('morning')); | ||
| } catch (err) { | ||
| console.error(err.message); | ||
| } | ||
|
|
||
|
|
||
| module.exports = tally; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.