Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions data-and-functions-1/src/functions/getActiveUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import DATA from '../DATA'
Copy link
Contributor

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.


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
20 changes: 20 additions & 0 deletions data-and-functions-1/src/functions/getMostExpensiveProduct.js
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you really want to make it explicit, you could just do:

let mostExpProd = undefined

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
28 changes: 28 additions & 0 deletions data-and-functions-1/src/functions/getOrderInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import DATA from '../DATA'
Copy link
Contributor

Choose a reason for hiding this comment

The 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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function only takes one parameter: DATA. Drop the orderId param.

if (DATA == null || DATA.users == null || orderId == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your second test should be testing for the existence of data.orders

return null
}
let orderInfoArr = []

for (let i = 0; i < DATA.orders.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the first line of your for loop:

const currentOrder = DATA.orders[i]

Then go from there...

const orderInfo = {
orderId: orderId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set orderId from the currentOrder's id property.

userName: userName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the userName the way you are setting it on line 19. Same with price, but use currentOrder instead of DATA.order.

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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete lines 17-21.

orderInfoArr.push(orderInfo)
}

return orderInfoArr
}

export default getOrderInfo
21 changes: 21 additions & 0 deletions data-and-functions-1/src/functions/getProductById.js
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
21 changes: 21 additions & 0 deletions data-and-functions-1/src/functions/getUserById.js
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