-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
executable file
·86 lines (77 loc) · 1.43 KB
/
data.js
File metadata and controls
executable file
·86 lines (77 loc) · 1.43 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
75
76
77
78
79
80
81
82
83
84
85
86
const firstName = [
'joe',
'jane',
'seb',
'alina',
'fabien',
'merwan',
'anna',
'annah',
'Fathma',
'Mohamed',
'Walid',
'Josiane',
undefined,
];
const lastName = [
'Dupont',
'Dupond',
'Durand',
'Kassir',
'Dalachra',
'Hussein',
'Wartani',
'Thoumsi',
'Angello',
undefined,
];
const companyNames = [
'apple',
'microsoft',
'Louis-vuitton',
'Nike',
'Channel',
'Dior',
'Slack',
'Uber'];
function createRandomNumber(min, max) {
return Math.floor(min + Math.random() * (max - min));
}
function getValue(array) {
return array[createRandomNumber(0, array.length + 2)];
}
function createCompany(name, index) {
const users = createUser(createRandomNumber(10, 50));
return {
name,
users,
isOpen: !!createRandomNumber(0, 2),
usersLength: users.length,
id: index,
};
}
function createUser(end) {
const tab = [];
for (let i = 0; i < end; i++) {
tab.push({
firstName: getValue(firstName),
lastName: getValue(lastName),
age: createRandomNumber(10, 120),
car: !!createRandomNumber(0, 2),
id: tab.length,
});
}
return tab;
}
let companies;
export function createAll() {
if (!companies) {
companies = companyNames.map(createCompany);
}
return companies;
}
export function cleanConsole(index, value) {
console.log(`---- EXAMPLE ${index} --- values before your modifications :`,
JSON.parse(JSON.stringify(value)),
);
}