forked from HackYourFuture/Assignments
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathex7-mindPrivacy.js
More file actions
57 lines (52 loc) · 1.25 KB
/
ex7-mindPrivacy.js
File metadata and controls
57 lines (52 loc) · 1.25 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
const employeeRecords = [
{
name: 'John',
occupation: 'developer',
gender: 'M',
email: 'john.doe@somewhere.net',
salary: 50000,
},
{
name: 'Jane',
occupation: 'manager',
gender: 'F',
email: 'jane.eyre@somewhere.net',
salary: 60000,
},
];
function filterPrivateData(employeesRecord) {
// const nonPrivateData = [];
// for (let { name, occupation, email } of employeesRecord) {
// nonPrivateData.push({ name, occupation, email });
// }
const nonPrivateData = employeesRecord.map(({ name, occupation, email }) => {
return { name, occupation, email };
});
return nonPrivateData;
}
function test1() {
console.log('Test 1: filterPrivateData should take one parameter');
console.assert(filterPrivateData.length === 1);
}
function test2() {
console.log('Test 2: gender and salary should be filtered out');
const expected = [
{
name: 'John',
occupation: 'developer',
email: 'john.doe@somewhere.net',
},
{
name: 'Jane',
occupation: 'manager',
email: 'jane.eyre@somewhere.net',
},
];
const result = filterPrivateData(employeeRecords);
console.assert(JSON.stringify(result) === JSON.stringify(expected));
}
function test() {
test1();
test2();
}
test();