-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-2.js
More file actions
executable file
·47 lines (38 loc) · 1.79 KB
/
example-2.js
File metadata and controls
executable file
·47 lines (38 loc) · 1.79 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {cleanConsole, createAll} from './data';
const companies = createAll();
// -----------------------------------------------------------------------------
// INSTRUCTIONS IN ENGLISH
// Create a function taking as parameter the variable "companies" and the
// boolean "hasCar". For each "company" you must keep only the
// "users" whose attribute value "car" is equal to the parameter of the
// "hasCar" function and the "usersLength" attribute must indicate the number of
// "users" corresponding to the "hasCar" parameter.
// -----------------------------------------------------------------------------
// INSTRUCCIONES EN ESPAÑOL
// Crear una función tomando como parámetro la variable "companies" y el
// booleano "hasCar". Para cada "company" debe conservar solo
// "users" cuyo valor de atributo "car" es igual al parámetro del
// función "hasCar" y el atributo "usersLength" deben indicar el total de
// "users" correspondientes al parámetro "hasCar".
// -----------------------------------------------------------------------------
// INSTRUCTIONS EN FRANÇAIS
// Créer une fonction prenant en paramètre la variable "companies" et le
// booléen "hasCar". Pour chaque "company" vous devez garder uniquement les
// "users" dont la valeur de l'attribut "car" est égal au paramètre de la
// fonction "hasCar" et l'attribut "usersLength" doit renseigner le nombre de
// "users" correspondant au paramètre "hasCar".
export default function f2(companies, hasCar) {
return companies.map(
(company) => {
const users = company.users.filter(
(u) => (u.car === hasCar),
);
return {
...company,
users,
usersLength: users.length,
};
});
};
cleanConsole(2, companies);
console.log('---- EXAMPLE 2 --- ', f2(companies, true));