-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-sum.out
More file actions
25 lines (21 loc) · 831 Bytes
/
Copy pathtest-sum.out
File metadata and controls
25 lines (21 loc) · 831 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
sum:
[] -> 0
[1] -> 1
[5, 1, 2, 3, 4] -> 15
["a", "b", "c"] -> 0
["20", "3"] -> 23
["3", "20"] -> 23
[20, 3] -> 23
[3, 20] -> 23
sum ignores null, undefined, and NaN:
[NaN, 1, 2, 3, 4, 5] -> 15
[1, 2, 3, 4, 5, NaN] -> 15
[10, null, 3, undefined, 5, NaN] -> 18
sum treats heterogenous types as numbers:
[20, "3"] -> 23
["20", 3] -> 23
[3, "20"] -> 23
["3", 20] -> 23
sum applies accessor function:
[1, 2, 3, 4, 5], [2, 4, 6, 8, 10] -> 45
[1, 2, 3, 4, 5] -> 10