-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapfunction.js
More file actions
64 lines (43 loc) · 1.2 KB
/
Copy pathmapfunction.js
File metadata and controls
64 lines (43 loc) · 1.2 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
/** 3. Create a Map to store contact information (name, age, email, location) and implement a function to
retrieve contact details by name. */
const contacts = new Map();
contacts.set('John Doe', {
age: 30,
email: 'johndoe@example.com',
location: 'New York',
});
contacts.set('Jane Smith', {
age: 25,
email: 'janesmith@example.com',
location: 'London',
});
contacts.set('Michael Johnson', {
age: 35,
email: 'michaeljohnson@example.com',
location: 'Sydney',
});
function getContactDetails(name) {
if (contacts.has(name)) {
return contacts.get(name);
} else {
return 'Contact not found.';
}
}
const contactName = 'Jane Smith';
const contactDetails = getContactDetails(contactName);
console.log(`Details for ${contactName}:`, contactDetails);
const unknownContact = 'Alice Brown';
const unknownContactDetails = getContactDetails(unknownContact);
console.log(`Details for ${unknownContact}:`, unknownContactDetails);
/** output ==
* Sorted ages: [
19, 19, 20, 22, 24,
24, 24, 25, 25, 26
]
Min age: 19
Max age: 26
Median age: 24
Average age: 22.8
07
07
Difference between max and average: 3.1999999999999993 */