質問編集履歴

2

groups 修正

2018/02/06 10:44

投稿

tommyTeratail
tommyTeratail

スコア31

test CHANGED
File without changes
test CHANGED
@@ -66,10 +66,6 @@
66
66
 
67
67
  {identify:'sports', id: 1},
68
68
 
69
- {identify:'sports', id: 2},
70
-
71
- {identify:'nature', id: 1},
72
-
73
69
  {identify:'nature', id: 2},
74
70
 
75
71
  ];

1

データ準備

2018/02/06 10:44

投稿

tommyTeratail
tommyTeratail

スコア31

test CHANGED
File without changes
test CHANGED
@@ -16,30 +16,94 @@
16
16
 
17
17
  ```javascript
18
18
 
19
- const make = (tmpList, groups) => {
19
+ const list = {
20
20
 
21
+ 'sports': [
22
+
23
+ {
24
+
25
+ identify: 'soccer',
26
+
27
+ name: 'サッカー',
28
+
29
+ },
30
+
31
+ {
32
+
33
+ identify: 'baseball',
34
+
35
+ name: '野球',
36
+
37
+ },
38
+
39
+ ],
40
+
41
+ 'nature': [
42
+
43
+ {
44
+
45
+ identify: 'animal',
46
+
47
+ name: '動物',
48
+
49
+ },
50
+
51
+ {
52
+
53
+ identify: 'flower',
54
+
21
- const list = [];
55
+ name: '花',
56
+
57
+ },
58
+
59
+ ],
60
+
61
+ };
22
62
 
23
63
 
24
64
 
25
- _.forEach(groups, group => {
65
+ const groups = [
26
66
 
27
- _.forEach(tmpList, v => {
67
+ {identify:'sports', id: 1},
28
68
 
29
- v['id'] = group.id;
69
+ {identify:'sports', id: 2},
30
70
 
31
- list.push(v);
71
+ {identify:'nature', id: 1},
32
72
 
33
- });
73
+ {identify:'nature', id: 2},
34
74
 
35
- });
75
+ ];
36
76
 
37
77
 
38
78
 
39
- return list;
79
+ const make = (tmpList, groups) => {
40
80
 
81
+ const list = [];
82
+
83
+ _.forEach(groups, group => {
84
+
85
+ _.forEach(tmpList[group.identify], v => {
86
+
87
+ v['group_id'] = group.id;
88
+
89
+ list.push(v);
90
+
41
- };
91
+ });
92
+
93
+ });
42
94
 
43
95
 
44
96
 
97
+ return list;
98
+
99
+ };
100
+
101
+
102
+
103
+ console.log(
104
+
105
+ make(list, groups)
106
+
107
+ );
108
+
45
109
  ```