-
Notifications
You must be signed in to change notification settings - Fork 11
Data and functions 1 #4
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: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import DATA from '../DATA' | ||
|
|
||
| const getActiveUsers = (DATA) => { | ||
| if (DATA == null || DATA.users == null) { | ||
| return null | ||
| } | ||
|
|
||
| let activeUsers = [] | ||
|
|
||
| DATA.users.forEach((user) => { | ||
| if (user.accountActive === true) { | ||
| activeUsers.push(user) | ||
| } | ||
| }) | ||
|
|
||
| return activeUsers | ||
| } | ||
|
|
||
| export default getActiveUsers | ||
|
|
||
| // passes | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import DATA from '../DATA' | ||
|
|
||
| const getMostExpensiveProduct = (DATA) => { | ||
| if (DATA == null || DATA.products == null) { | ||
| return null | ||
| } | ||
| let mostExpProd // = undefined | ||
|
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 really want to make it explicit, you could just do: but putting in the comment is also good form. |
||
|
|
||
| for (let i = 0; i < DATA.products.length; i++) { | ||
| if (mostExpProd === undefined || DATA.products[i].price > mostExpProd.price) { | ||
| mostExpProd = DATA.products[i] | ||
| } | ||
| } | ||
|
|
||
| return mostExpProd | ||
| } | ||
|
|
||
| export default getMostExpensiveProduct | ||
|
|
||
| // passes | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import DATA from '../DATA' | ||
|
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. Don't import DATA! It's being passed to you. |
||
| import getProductById from './getProductById' | ||
| import getUserById from './getUserById' | ||
|
|
||
| const getOrderInfo = (DATA, orderId) => { | ||
|
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 only takes one parameter: |
||
| if (DATA == null || DATA.users == null || orderId == null) { | ||
|
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. Your second test should be testing for the existence of |
||
| return null | ||
| } | ||
| let orderInfoArr = [] | ||
|
|
||
| for (let i = 0; i < DATA.orders.length; i++) { | ||
|
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. Make the first line of your Then go from there... |
||
| const orderInfo = { | ||
| orderId: orderId, | ||
|
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. Set |
||
| userName: userName, | ||
|
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. Set the |
||
| price: price | ||
| } | ||
| if (DATA.orders.id && DATA.orders.userId && DATA.orders.productId > 0) { | ||
| let orderId = DATA.orders.id | ||
| let userName = getUserById(DATA.orders.userId).name | ||
| let price = getProductById(DATA.order.productId).price | ||
| } | ||
|
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. Delete lines 17-21. |
||
| orderInfoArr.push(orderInfo) | ||
| } | ||
|
|
||
| return orderInfoArr | ||
| } | ||
|
|
||
| export default getOrderInfo | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import DATA from '../DATA' | ||
|
|
||
| const getProductByID = (DATA, id) => { | ||
| if (DATA == null || DATA.products == null || id == null) { | ||
| return null | ||
| } | ||
| let productFound | ||
|
|
||
| for (let i = 0; i < DATA.products.length; i++) { | ||
| const currentProduct = DATA.products[i] | ||
|
|
||
| if (currentProduct.id === id) { | ||
| productFound = currentProduct | ||
| } | ||
| } | ||
| return productFound | ||
| } | ||
|
|
||
| export default getProductByID | ||
|
|
||
| //passes |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import DATA from '../DATA' | ||
|
|
||
| const getUserById = (DATA, id) => { | ||
| if (DATA == null || DATA.users == null || id == null) { | ||
| return null | ||
| } | ||
|
|
||
| let foundUser | ||
|
|
||
| for (let i = 0; i < DATA.users.length; i++) { | ||
| const currentUser = DATA.users[i] | ||
|
|
||
| if (currentUser.id === id) { | ||
| foundUser = currentUser | ||
| } | ||
| } | ||
| return foundUser | ||
| } | ||
| export default getUserById | ||
|
|
||
| // passes |
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.
Don't import DATA! You can remove this import from all of your answer files.