Created
August 6, 2023 14:40
-
-
Save modos/a2110351d23f5f7d60688efc84086381 to your computer and use it in GitHub Desktop.
لیست کاربران
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import users from './users.json' | |
import UserItem from './UserItem' | |
import AverageAge from './AverageAge' | |
const UserList = () => { | |
const cUsers = users.filter(user => user.role === 'user'); | |
const cAdmins = users.filter(user => user.role === 'admin'); | |
const sum = cAdmins.reduce((acc, cur) => { | |
return acc + cur.age; | |
}, 0) | |
const avg = sum / cAdmins.length; | |
return( | |
<div> | |
{cUsers.map(user => <UserItem name={user.name}/>)} | |
<AverageAge average={avg}/> | |
</div> | |
) | |
} | |
export default UserList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment