-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
37 lines (30 loc) · 974 Bytes
/
javascript.js
File metadata and controls
37 lines (30 loc) · 974 Bytes
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
// --- Constants & Utilities ---
const delay = ms => new Promise(res => setTimeout(res, ms));
const users = [
{ id: 1, name: "Alice", active: true },
{ id: 2, name: "Bob", active: false },
{ id: 3, name: "Charlie", active: true }
];
// --- Async Function with Fetch ---
async function fetchUserData(id) {
console.log(`Fetching data for user ${id}...`);
await delay(500); // fake delay
return { email: `${id}@example.com`, lastLogin: new Date() };
}
// --- Main Logic ---
(async () => {
const activeUsers = users.filter(u => u.active);
for (const user of activeUsers) {
const { id, name } = user;
const data = await fetchUserData(id);
const summary = {
id,
name,
email: data.email,
lastLogin: data.lastLogin.toISOString()
};
console.log(
`👤 ${name} (${id})\n📧 ${summary.email}\n🕒 ${summary.lastLogin}\n`
);
}
})();