回答編集履歴
1
追記
test
CHANGED
@@ -47,3 +47,53 @@
|
|
47
47
|
[(8+0)%(n+1),(8+1)%(n+1),(8+2)%(n+1)]
|
48
48
|
|
49
49
|
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
# 追記
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```JavaScript
|
58
|
+
|
59
|
+
const n = 9;
|
60
|
+
|
61
|
+
const rows = n + 1;
|
62
|
+
|
63
|
+
const columns = 3;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
let exclude = [...Array(columns).keys()].map(column => []);
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
const dest = [...Array(rows).keys()].map(row => {
|
72
|
+
|
73
|
+
let result = [];
|
74
|
+
|
75
|
+
for (let i = 0; i < columns; i++) {
|
76
|
+
|
77
|
+
let array = [...Array(rows).keys()].
|
78
|
+
|
79
|
+
filter(a => exclude[i].findIndex(b => a === b) < 0).
|
80
|
+
|
81
|
+
filter(a => result.findIndex(b => a === b) < 0);
|
82
|
+
|
83
|
+
const r = Math.floor(Math.random() * array.length);
|
84
|
+
|
85
|
+
result.push(array[r]);
|
86
|
+
|
87
|
+
exclude[i].push(array[r]);
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
return result;
|
92
|
+
|
93
|
+
});
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
console.log(dest);
|
98
|
+
|
99
|
+
```
|