11import { cleanConsole , createAll } from './data' ;
22const companies = createAll ( ) ;
33
4- const f2 = ( companies , hasCar ) => {
5- return companies . map ( ( company ) => {
6- const users = company . users . filter ( ( u ) => {
7- return ( u . car === hasCar ) ;
8- } ) ;
9-
10- return {
11- ...company ,
12- users,
13- usersLength : users . length ,
14- } ;
15- } ) ;
4+ export default function f2 ( companies , hasCar ) {
5+ return companies . map (
6+ ( company ) => {
7+ const users = company . users . filter (
8+ ( u ) => ( u . car === hasCar ) ,
9+ ) ;
10+
11+ return {
12+ ...company ,
13+ users,
14+ usersLength : users . length ,
15+ } ;
16+ } ) ;
1617} ;
1718
1819cleanConsole ( 2 , companies ) ;
19- console . log ( '---- EXAMPLE 2 --- ' , f2 ( companies , false ) ) ;
20-
21- // -----------------------------------------------------------------------------
22- // INSTRUCCIONES EN ESPAÑOL
23-
24- // Crear una función tomando como parámetro la variable "companies" y el
25- // booleano "hasCar". Para cada "company" debe conservar solo
26- // "users" cuyo valor de atributo "car" es igual al parámetro del
27- // función "hasCar" y el atributo "usersLength" deben indicar el total de
28- // "users" correspondientes al parámetro "hasCar".
20+ console . log ( '---- EXAMPLE 2 --- ' , f2 ( companies , true ) ) ;
2921
3022// -----------------------------------------------------------------------------
3123// INSTRUCTIONS IN ENGLISH
@@ -36,6 +28,15 @@ console.log('---- EXAMPLE 2 --- ', f2(companies, false));
3628// "hasCar" function and the "usersLength" attribute must indicate the number of
3729// "users" corresponding to the "hasCar" parameter.
3830
31+ // -----------------------------------------------------------------------------
32+ // INSTRUCCIONES EN ESPAÑOL
33+
34+ // Crear una función tomando como parámetro la variable "companies" y el
35+ // booleano "hasCar". Para cada "company" debe conservar solo
36+ // "users" cuyo valor de atributo "car" es igual al parámetro del
37+ // función "hasCar" y el atributo "usersLength" deben indicar el total de
38+ // "users" correspondientes al parámetro "hasCar".
39+
3940// -----------------------------------------------------------------------------
4041// INSTRUCTIONS EN FRANÇAIS
4142
0 commit comments