-
Notifications
You must be signed in to change notification settings - Fork 0
/
index4.js
65 lines (44 loc) · 1.1 KB
/
index4.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
// let add = (a,b,c) => parseFloat(a) + parseFloat(b) + parseFloat(c);
let add = (...a) =>{
//console.log("a="+ a); not good
console.log("a =", a);
let sum = 0
for (let i=0;i < a.length; i++) {
sum+= a[i];
//sum = a[i] + sum;
}
return sum;
}
//console.log(add(1,2,3));
// let minus = (...a) =>{
// //console.log("a="+ a); not good
// console.log("a =", a);
// let sum = a[0]
// for ( i=1;i < a.length; i++) {
// sum-= a[i];
// //sum = sum - a[i];
// }
// return sum;
// }
let minus = (sum,...a) =>{
//console.log("a="+ a); not good
console.log("sum = ", sum, "a =", a);
for ( i=0;i < a.length; i++) {
sum-= a[i];
//sum = sum - a[i];
}
return sum;
}
//console.log(minus(1,2,3));
let calcul = (fn,nombres) => {
return fn(...nombres);
}
console.log(calcul(add, [1,2,3]));
let n = [1,2,3];
let n2 = [n];
let n3 = [...n];
let n4 = [...n, n, ...n];
console.log('n:', n);
console.log('n2:', n2);
console.log('n3:', n3);
console.log('n4:', n4);