回答編集履歴
3
コメントを受けてIDをユニークに
answer
CHANGED
@@ -14,4 +14,27 @@
|
|
14
14
|
)
|
15
15
|
)]
|
16
16
|
);
|
17
|
+
```
|
18
|
+
|
19
|
+
### コメントを受けてIDをユニークに
|
20
|
+
```javascript
|
21
|
+
(
|
22
|
+
( {itemDict, productsIds} ) =>
|
23
|
+
[...new Set(
|
24
|
+
[].concat(
|
25
|
+
...productsIds.map( e => itemDict[e] )
|
26
|
+
).map( e => JSON.stringify(e) )
|
27
|
+
)].map( e => JSON.parse(e) )
|
28
|
+
)({
|
29
|
+
itemDict:
|
30
|
+
Object.assign( ...itemList.map( ({id,items}) => ({[id]:items}) ) )
|
31
|
+
,
|
32
|
+
productsIds:
|
33
|
+
[...new Set(
|
34
|
+
[].concat(
|
35
|
+
...orderList.map( ({products}) => products )
|
36
|
+
)
|
37
|
+
)]
|
38
|
+
,
|
39
|
+
});
|
17
40
|
```
|
2
こっちのほうがスマートかな……
answer
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
...productsIds.map( e => itemDict[e] )
|
8
8
|
)
|
9
9
|
)(
|
10
|
-
|
10
|
+
Object.assign( ...itemList.map( ({id,items}) => ({[id]:items}) ) ),
|
11
11
|
[...new Set(
|
12
12
|
[].concat(
|
13
13
|
...orderList.map( ({products}) => products )
|
1
こっちのほうが読みやすい、かな?
answer
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
あえて工夫するとするなら、とりあえず`itemList`を辞書化するとか?
|
3
3
|
```javascript
|
4
4
|
(
|
5
|
-
( itemDict,
|
5
|
+
( itemDict, productsIds ) =>
|
6
6
|
[].concat(
|
7
|
-
...[...new Set(
|
8
|
-
[].concat(
|
9
|
-
...orderList.map( ({products}) => products )
|
10
|
-
)
|
11
|
-
|
7
|
+
...productsIds.map( e => itemDict[e] )
|
12
8
|
)
|
13
9
|
)(
|
14
10
|
itemList.reduce( (d, {id,items}) => ( d[id]=items,d ), {} ),
|
11
|
+
[...new Set(
|
15
|
-
|
12
|
+
[].concat(
|
13
|
+
...orderList.map( ({products}) => products )
|
14
|
+
)
|
15
|
+
)]
|
16
16
|
);
|
17
17
|
```
|