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
1 change: 1 addition & 0 deletions data-and-functions-1/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'
const App = () =>
<div>
<h1 style={{textAlign: 'center'}}>Data and Functions Workshop #1</h1>
<h2>Great weather today!</h2>
Copy link
Contributor

Choose a reason for hiding this comment

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

No, it rained today.

</div>

export default App
19 changes: 19 additions & 0 deletions data-and-functions-1/src/functions/getUserById.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const getUserById = (data, userId) => {
if (userId == null) {
return null
}
if (data == null) {
return null
}
if (data.users == null) {
return null
}
Copy link
Contributor

Choose a reason for hiding this comment

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

See if you can combine these three tests into one if using the boolean OR operator ||

for (let i = 0; i < data.users.length; i += 1) {
const currentUser = data.users[i]
if (currentUser.id === userId) {
return currentUser
}
}
}

export default getUserById