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

質問編集履歴

2

groups 修正

2018/02/06 10:44

投稿

tommyTeratail
tommyTeratail

スコア31

title CHANGED
File without changes
body CHANGED
@@ -32,8 +32,6 @@
32
32
 
33
33
  const groups = [
34
34
  {identify:'sports', id: 1},
35
- {identify:'sports', id: 2},
36
- {identify:'nature', id: 1},
37
35
  {identify:'nature', id: 2},
38
36
  ];
39
37
 

1

データ準備

2018/02/06 10:44

投稿

tommyTeratail
tommyTeratail

スコア31

title CHANGED
File without changes
body CHANGED
@@ -7,17 +7,49 @@
7
7
 
8
8
 
9
9
  ```javascript
10
- const make = (tmpList, groups) => {
11
- const list = [];
10
+ const list = {
11
+ 'sports': [
12
+ {
13
+ identify: 'soccer',
14
+ name: 'サッカー',
15
+ },
16
+ {
17
+ identify: 'baseball',
18
+ name: '野球',
19
+ },
20
+ ],
21
+ 'nature': [
22
+ {
23
+ identify: 'animal',
24
+ name: '動物',
25
+ },
26
+ {
27
+ identify: 'flower',
28
+ name: '花',
29
+ },
30
+ ],
31
+ };
12
32
 
13
- _.forEach(groups, group => {
33
+ const groups = [
14
- _.forEach(tmpList, v => {
15
- v['id'] = group.id;
34
+ {identify:'sports', id: 1},
16
- list.push(v);
35
+ {identify:'sports', id: 2},
36
+ {identify:'nature', id: 1},
37
+ {identify:'nature', id: 2},
17
- });
38
+ ];
18
- });
19
39
 
40
+ const make = (tmpList, groups) => {
20
- return list;
41
+ const list = [];
42
+ _.forEach(groups, group => {
43
+ _.forEach(tmpList[group.identify], v => {
44
+ v['group_id'] = group.id;
45
+ list.push(v);
21
- };
46
+ });
47
+ });
22
48
 
49
+ return list;
50
+ };
51
+
52
+ console.log(
53
+ make(list, groups)
54
+ );
23
55
  ```