-
Notifications
You must be signed in to change notification settings - Fork 11
added the 5 functions to test #10
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,13 @@ | ||
| import DATA from '../DATA' | ||
|
|
||
| const getActiveUsers = (id) => { | ||
|
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. Add a data parameter as the first parameter.
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. Sanity check the parameters according to the |
||
| let activeUserArray = [] | ||
| DATA.users.forEach((u) => { | ||
| if (u.accountActive === true) { | ||
| activeUserArray.push(u) | ||
| } | ||
| }) | ||
| return activeUserArray | ||
| } | ||
|
|
||
| export default getActiveUsers | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| 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. Remove the import. |
||
|
|
||
| const getMostExpensiveProduct = (data) => { | ||
| if (data == 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. This check is correct, but you need one more I think. |
||
| return null | ||
| } | ||
| let mostExpensiveProduct = 0 | ||
|
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. There are many ways to solve this one. You need to declare a variable like you did, but let's not initialize it: |
||
| DATA.products.forEach((m) => { | ||
|
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 |
||
| const currentProduct = data.products[m] | ||
|
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 this line. |
||
| if (currentProduct.price > mostExpensiveProduct) { | ||
|
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. Two things need to change here:
If either of those are true, enter your |
||
| mostExpensiveProduct = currentProduct | ||
| } | ||
| }) | ||
| return mostExpensiveProduct | ||
| } | ||
|
|
||
| export default getMostExpensiveProduct | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import getUserById from './getUserById' | ||
| import getProductById from './getProductById' | ||
|
|
||
| const getOrderInfo = (DATA) => { | ||
| if (DATA == null || DATA.orders == null) { | ||
| return null | ||
| } | ||
| const orderArray = [] | ||
| DATA.orders.forEach((o) => { | ||
|
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. Replace the |
||
| const currentOrder = DATA.orders[o] | ||
|
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 this |
||
| const userName = getUserById(DATA, currentOrder.userId).name | ||
| const orderId = currentOrder.id | ||
| const price = getProductById(DATA, currentOrder.productId).price | ||
| const orderInfo = { | ||
| orderId: orderId, | ||
| userName: userName, | ||
| price: price | ||
| } | ||
| orderArray.push(orderInfo) | ||
| }) | ||
| return orderArray | ||
| } | ||
|
|
||
| export default getOrderInfo | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 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. You don't need to |
||
|
|
||
| const getProductById = (id) => { | ||
|
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 expected function signature is:
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. You also need to test to make sure |
||
| let product | ||
| for (let n = 0; n < DATA.products.length; n += 1) { | ||
|
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. It's standard practice to use the variable name |
||
| if (DATA.products[n].id === id) { | ||
| product = DATA.products[n] | ||
| } | ||
| } | ||
| return product | ||
| } | ||
|
|
||
| export default getProductById | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| const getUserById = (DATA, userId) => { | ||
| let user | ||
| if (userId == null || DATA == null || DATA.users == null) { | ||
| return null | ||
| } else { | ||
| DATA.users.forEach((u) => { | ||
| if (u.userId === DATA.id) { | ||
|
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. You don't want to test against |
||
| user = u | ||
| } | ||
| }) | ||
| } | ||
| return user | ||
| } | ||
|
|
||
| export default getUserById | ||
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.
You don't need to pass in the data. The first parameter of all of your functions should be the data.