回答編集履歴

1

ちょうせい

2021/07/29 09:59

投稿

yambejp
yambejp

スコア116724

test CHANGED
@@ -9,3 +9,39 @@
9
9
  console.log(result);
10
10
 
11
11
  ```
12
+
13
+ # 分解したサンプル
14
+
15
+
16
+
17
+ ```javascript
18
+
19
+ const lines=[1,4,12,20,27];
20
+
21
+ const result=lines.reduce((accumulator,currentValue,index)=>{
22
+
23
+ console.log([accumulator,currentValue,index]);//デバグ用
24
+
25
+ let arr;
26
+
27
+ if(accumulator instanceof Array){
28
+
29
+ arr=accumulator;
30
+
31
+ }else{
32
+
33
+ arr=[];
34
+
35
+ }
36
+
37
+ let previousValue=lines[index-1];
38
+
39
+ arr=arr.concat([currentValue-previousValue]);
40
+
41
+ return arr;
42
+
43
+ });
44
+
45
+ console.log(result);
46
+
47
+ ```