forked from halitkalayci/js-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestAndSpread.js
60 lines (54 loc) · 1.41 KB
/
restAndSpread.js
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
export function sizCevapVerin() {
return [10, 20, 30, 40, 50];
}
// Rest Operator
// parametrelerinizi bir diziye dönüştürür, toparlar.
export function sum(...numbers) {
//console.info("number3:", Number(number3));
let total = 0;
for (let i = 0; i < numbers.length; i++) {
//total = total + numbers[i];
total += numbers[i]; // [10, 20, 30, 40, 50]
}
//return numbers.reduce((total, number) => total + number, 0);
return total;
}
function avg(cevapVerenKisiSayisi, ...numbers) {
return sum(...numbers) / cevapVerenKisiSayisi;
}
// Spread Operator
// bir dizi elemanlarını tek tek parametre olarak gönderir, yani birbirinden ayrıştırır.
export const cevaplariniz = sizCevapVerin();
const result = avg(26, ...cevaplariniz);
console.log(result);
// console.log(Math.max(...cevaplariniz));
// 010, 20, 30, 40, 50
function sayMyName(...letters) {
for (const letter of letters) {
console.log(letter);
}
}
sayMyName(...Object.keys({ first: "A", second: "H" }));
//
let instructor = {
firstName: "Ahmet",
lastName: "Çetinkaya",
};
let student = {
firstName: "Anıl",
lastName: "Kavuk",
};
const learningTopic = {
topic: ["JavaScript"], // 0x101
};
student = {
// firstName: "Anıl",
// lastName: "Kavuk",
...student,
//topic: 0x101
...learningTopic,
};
// Object.assign(instructor, student);
learningTopic.topic.push("Angular");
console.log(instructor);
console.log(student);