exercise 2.4

This commit is contained in:
Anish Lakhwara 2023-05-15 23:47:23 +10:00
parent 10daad2d87
commit 2850cda94b

View file

@ -15,28 +15,32 @@ const Content = ({ parts }) => {
}
const Sum = ({ parts }) => {
// Already used reduce :3
const total = parts.reduce((acc, currVal) => acc + currVal.exercises, 0)
return (
<b>The total number of execrcises is {total}</b>
)
}
const Course = ({ course }) => {
const Course = ({ courses }) => {
return (
<>
{courses.map(course =>
<>
<Header content={course.name} />
<Content parts={course.parts} />
<Sum parts={course.parts} />
</>
)}
</>
)
}
function App() {
const course = {
id: 1,
const courses = [
{
name: 'Half Stack application development',
id: 1,
parts: [
{
name: 'Fundamentals of React',
@ -59,9 +63,26 @@ function App() {
id: 4
}
]
},
{
name: 'Node.js',
id: 2,
parts: [
{
name: 'Routing',
exercises: 3,
id: 1
},
{
name: 'Middlewares',
exercises: 7,
id: 2
}
]
}
]
return <Course course={course} />
return <Course courses={courses} />
}
export default App;