diff --git a/data-and-functions-1/src/App.js b/data-and-functions-1/src/App.js index 8353dfe..7afb1e0 100644 --- a/data-and-functions-1/src/App.js +++ b/data-and-functions-1/src/App.js @@ -3,6 +3,7 @@ import React from 'react' const App = () =>

Data and Functions Workshop #1

+

Great weather today!

export default App diff --git a/data-and-functions-1/src/functions/getUserById.js b/data-and-functions-1/src/functions/getUserById.js new file mode 100644 index 0000000..cb4c2f6 --- /dev/null +++ b/data-and-functions-1/src/functions/getUserById.js @@ -0,0 +1,19 @@ +const getUserById = (data, userId) => { + if (userId == null) { + return null + } + if (data == null) { + return null + } + if (data.users == null) { + return null + } + for (let i = 0; i < data.users.length; i += 1) { + const currentUser = data.users[i] + if (currentUser.id === userId) { + return currentUser + } + } +} + +export default getUserById