-
-
Notifications
You must be signed in to change notification settings - Fork 283
Glasgow| 2026-ITP-Jan | Tuan Nguyen| Sprint 2 | Objects #1204
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 11 commits
7a32b22
25def28
2ff2c05
eaffafc
4d7b72c
9251977
33d17a2
db07953
2a3243b
ccce688
5cf4592
fcfb3ef
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,30 @@ | ||
| function contains() {} | ||
| function contains(object, key) { | ||
| if ( | ||
| object === null || | ||
| object === undefined || | ||
| typeof object !== "object" || | ||
| Array.isArray(object) | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
| ) { | ||
| return false; | ||
| } | ||
|
|
||
| if (Object.keys(object).length === 0) { | ||
| return false; | ||
| } | ||
|
|
||
| for (const item in object) { | ||
| if (Array.isArray(object[item])) { | ||
| return false; | ||
| } | ||
| } | ||
|
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. The function is supposed to check only if
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. THank you for your feed back. I have make some change to make sure the function operate what is suppose to do: function contains(object, key) { if (Object.keys(object).length === 0) { for (const item in object) { |
||
|
|
||
| for (const item in object) { | ||
| if (item === key) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| module.exports = contains; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| function createLookup() { | ||
| function createLookup(pairs) { | ||
| // implementation here | ||
| let countryPair = {}; | ||
| for (const [country, currency] of pairs) { | ||
| countryPair[country] = currency; | ||
| } | ||
|
|
||
| return countryPair; | ||
| } | ||
|
|
||
| module.exports = createLookup; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,16 @@ | ||
| function tally() {} | ||
|
|
||
| function tally(sumArray) { | ||
| if (sumArray.length === 0) return {}; | ||
| if (!Array.isArray(sumArray)) { | ||
| throw new Error("Input musk be an array"); | ||
| } | ||
|
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
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. Thank you for the feed back here is my solution: function tally(sumArray) { if (sumArray.length === 0) return {}; let totalSum = {}; |
||
| let totalSum = {}; | ||
| for (const item of sumArray) { | ||
| if (!Object.hasOwn(totalSum, item)) { | ||
| totalSum[item] = 1; | ||
| } else { | ||
| totalSum[item] += 1; | ||
| } | ||
| } | ||
|
cjyuan marked this conversation as resolved.
|
||
| return totalSum; | ||
| } | ||
| module.exports = tally; | ||
Uh oh!
There was an error while loading. Please reload this page.