回答編集履歴
3
オブジェクトに戻さないなら、groupByToMap がいいかな?
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
~~Array.prototype.groupBy()~~ `Array.prototype.groupByToMap`を使ってみました。
|
2
2
|
|
3
3
|
```html
|
4
4
|
<!DOCTYPE html>
|
@@ -18,17 +18,15 @@
|
|
18
18
|
[103, ["nakamura"]],
|
19
19
|
]
|
20
20
|
console.log(
|
21
|
-
Object.entries(
|
22
|
-
|
21
|
+
[...test.groupByToMap(([key,]) => key)].map(
|
23
|
-
).map(
|
24
22
|
([key, value]) => [key, value.flatMap(x => x[1])]
|
25
23
|
)
|
26
24
|
)
|
25
|
+
|
27
26
|
</script>
|
28
27
|
</body>
|
29
28
|
|
30
29
|
</html>
|
31
30
|
```
|
32
31
|
|
33
|
-
[Array.prototype.groupBy() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/groupBy)
|
34
|
-
[core-js-bundle CDN by jsDelivr - A CDN for npm and GitHub](https://www.jsdelivr.com/package/npm/core-js-bundle)
|
32
|
+
[Array.prototype.groupByToMap() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/groupByToMap)[core-js-bundle CDN by jsDelivr - A CDN for npm and GitHub](https://www.jsdelivr.com/package/npm/core-js-bundle)
|
2
つい手拍子でオブジェクトにしてしまっていたのを修正
test
CHANGED
@@ -18,12 +18,10 @@
|
|
18
18
|
[103, ["nakamura"]],
|
19
19
|
]
|
20
20
|
console.log(
|
21
|
-
Object.fromEntries(
|
22
|
-
|
21
|
+
Object.entries(
|
23
|
-
|
22
|
+
test.groupBy(([key,]) => key)
|
24
|
-
|
23
|
+
).map(
|
25
|
-
|
24
|
+
([key, value]) => [key, value.flatMap(x => x[1])]
|
26
|
-
)
|
27
25
|
)
|
28
26
|
)
|
29
27
|
</script>
|
1
見やすくしよう。
test
CHANGED
@@ -18,9 +18,14 @@
|
|
18
18
|
[103, ["nakamura"]],
|
19
19
|
]
|
20
20
|
console.log(
|
21
|
+
Object.fromEntries(
|
22
|
+
Object.entries(
|
23
|
+
test.groupBy(([key,]) => key)
|
24
|
+
).map(
|
21
|
-
|
25
|
+
([key, value]) => [key, value.flatMap(x => x[1])]
|
26
|
+
)
|
27
|
+
)
|
22
28
|
)
|
23
|
-
|
24
29
|
</script>
|
25
30
|
</body>
|
26
31
|
|