-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoru7.ts
More file actions
30 lines (25 loc) · 895 Bytes
/
Copy pathSoru7.ts
File metadata and controls
30 lines (25 loc) · 895 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
type User = { id: number; name: string; email: string };
const users: User[] = [
{ id: 1, name: "Ali", email: "ali@mail.com" },
{ id: 2, name: "Ayşe", email: "ayse@mail.com" },
];
// (Soru 5'teki User tipini ve users dizisini kullanın)
function updateUser(
id: number,
updates: Partial<User>
): Readonly<User> | undefined {
const user = users.find((u) => u.id === id);
if (!user) {
return undefined;
}
const updated = { ...user, ...updates };
return updated;
// 'user' nesnesini 'updates' ile birleştirin (Object.assign veya ...)
// ve güncellenmiş kullanıcıyı döndürün
}
console.log("Eski: ", users[0]);
const updatedUser = updateUser(1, { email: "ali.yeni@mail.com" });
console.log("Yeni: ", updatedUser);
// BEKLENEN EKRAN ÇIKTISI:
// Eski: { id: 1, name: 'Ali', email: 'ali@mail.com' }
// Yeni: { id: 1, name: 'Ali', email: 'ali.yeni@mail.com' }