Created
April 8, 2021 16:01
-
-
Save jordanhudgens/594f96cfd50475331eedde28e2be3edb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type EmployeeType = { | |
email: string; | |
roles?: string[]; | |
} | |
let data: {employees?: EmployeeType[]}; | |
data = { | |
employees: [ | |
{email: "[email protected]", roles: ["admin", "superAdmin"]}, | |
{email: "[email protected]"}, | |
{email: "[email protected]"}, | |
] | |
} | |
// let formattedEmployees; | |
// if (data && data.employees) { | |
// formattedEmployees = data.employees.map((employee: EmployeeType) => { | |
// let roles; | |
// if (employee.roles) { | |
// roles = employee.roles.join(", "); | |
// } | |
// return `${employee.email.toUpperCase()} ${roles}`; | |
// }) | |
// } | |
const formattedEmployees = data?.employees?.map((employee: EmployeeType) => { | |
return `${employee.email.toUpperCase()} ${employee.roles?.join(", ")}`; | |
}) | |
console.log(formattedEmployees) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment