-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-3.js
More file actions
executable file
·74 lines (60 loc) · 2.56 KB
/
example-3.js
File metadata and controls
executable file
·74 lines (60 loc) · 2.56 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {cleanConsole, createAll} from './data';
import f1 from './example-1';
const companies = createAll();
// -----------------------------------------------------------------------------
// INSTRUCTIONS IN ENGLISH
// Create a function taking the "companies" variable as a parameter and returning
// a boolean validating that all the names of the companies and the attributes "firstName"
// and "lastName" of "users" are capitalized. You must test the operation
// of this function by importing the function created for "example-1.js".
// -----------------------------------------------------------------------------
// INSTRUCCIONES EN ESPAÑOL
// Cree una función tomando la variable "companies" como parámetro y devolviendo
// un booleano que valida que todos los nombres de las empresas y los atributos
// "firstName" y "lastName" de "users" están en mayúsculas.
// Debes probar la operación de esta función importando la función creada
// en el "example-1.js".
// -----------------------------------------------------------------------------
// INSTRUCTIONS EN FRANÇAIS
// Créer une fonction prenant en paramètre la variable "companies" et renvoyant
// un booléen validant que tous les noms des "company" et les attributs "firstName"
// et "lastName" des "users" sont en majuscules. Vous devez tester le fonctionnement
// de cette fonction en important la fonction créée pour "example-1.js".
const isCapitalized = (s) => (s.charAt(0) === s.charAt(0).toUpperCase());
const f3 = (companies, hasCar) => {
return (
companies.find(
(company) => {
// Check company name
if (
!isCapitalized(company.name)
) return true;
return (
company.users.find(
(user) => {
// Check first name
if (
(
typeof user.firstName === 'string'
|| user.firstName instanceof String
)
&& !isCapitalized(user.firstName)
) return true;
// Check last name
if (
(
typeof user.lastName === 'string'
|| user.lastName instanceof String
)
&& !isCapitalized(user.lastName)
) return true;
return false;
},
) !== undefined
);
},
) === undefined
);
};
cleanConsole(3, companies);
console.log('---- EXAMPLE 3 --- ', f3(companies), f3(f1(companies)));