teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

テキスト修正

2019/12/18 05:40

投稿

jun68ykt
jun68ykt

スコア9058

answer CHANGED
@@ -5,12 +5,14 @@
5
5
  ### (1) reduce を使う
6
6
  ```javascript
7
7
  var arr2 = arr.reduce(
8
- (a, e) => a[a.length-1].length === 4 ?
8
+ (a, e, i) => i % 4 ?
9
- [...a, [e]] : [...a.slice(0, a.length-1), [...a[a.length-1], e] ]
9
+ [...a.slice(0, a.length-1), [...a[a.length-1], e] ]
10
+ :
11
+ [...a, [e]]
10
- ,[[]]
12
+ ,[]
11
13
  )
12
14
  ```
13
- - 動作確認用 CodePen: [https://codepen.io/jun68ykt/pen/JjoERKx?editors=0012](https://codepen.io/jun68ykt/pen/JjoERKx?editors=0012)
15
+ - 動作確認用 CodePen: [https://codepen.io/jun68ykt/pen/dyPNpEM?editors=0012](https://codepen.io/jun68ykt/pen/dyPNpEM?editors=0012)
14
16
 
15
17
 
16
18
  ### (2) lodash の [_.chunk](https://lodash.com/docs/4.17.15#chunk) を使う