-
-
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
a5f25c7
ca26a21
b8b5c2c
3339f76
d25f0a1
4b2cca7
9fcea26
bac8a52
a25d8cf
87488ee
587a287
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,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; |
| 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; | ||
| 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; | ||
| 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; | ||
| } | ||
|
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. Code is not yet properly indented. Can you fix the identation? If you have enabled "Format on save" but it is not working, it is likely that you haven't assign a formatter for JS file. This could happen if you have zero or multiple extensions that can format .js file. If you have installed "Prettier" extension. To assign it as the formatter of JS code, you can try:
Author
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. sorry sometimes i forgot about indention syntax because i pay more attention on node running, the rule is about 2 standard space for indentation and allign the parallel function
Author
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. i would put comment on after i correct my code according PR guide which give me another chance to review correction. What is more, i know what is the reason for correction later on.
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. If you have successfully enabled "Format on save" and assign "Prettier" as your JS code formatter on VSCode, you won't have to worry about indentation and code format anymore. |
||
|
|
||
| console.log(tally([ 2,"bee",2,"apple","apple",2, "banana"])) | ||
|
|
||
| try { | ||
| console.log(tally('morning')); | ||
| } catch (err) { | ||
| console.error(err.message); | ||
| } | ||
|
|
||
|
|
||
| module.exports = tally; | ||
Uh oh!
There was an error while loading. Please reload this page.