-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap-exercise.js
More file actions
30 lines (30 loc) · 913 Bytes
/
map-exercise.js
File metadata and controls
30 lines (30 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Napisz funkcję toFullNames, która zamienia listę użytkowników na listę ich
// pełnych imion i nazwisk w formacie "{imię} {drugie imię} {nazwisko}",
// lub "{imię} {nazwisko}" jeśli nie ma drugiego imienia. Załóż, że użytkownicy
// mają właściwości firstName, lastName o typie string, oraz secondName
// typu string lub undefined.
// solution:
function toFullNamesUsers(users) {
return users.map(function (user) {
if (user.secondName) {
return `${user.firstName} ${user.secondName} ${user.lastName}`;
} else {
return `${user.firstName} ${user.lastName}`;
}
});
}
const users = [
{ firstName: "Turanga", lastName: "Leela" },
{ firstName: "Amy", lastName: "Wong" },
{
firstName: "Philip",
secondName: "Jay",
lastName: "Fry",
},
{
firstName: "Bender",
secondName: "Bending",
lastName: "Rodríguez",
},
];
toFullNamesUsers(users);