回答編集履歴
1
HTML部分を追加
test
CHANGED
@@ -1,8 +1,60 @@
|
|
1
1
|
解法は知りませんが根幹となりませんか?
|
2
|
+
|
3
|
+
応用の仕方の例も掲載し、ちょっと手直ししました。
|
2
4
|
|
3
5
|
|
4
6
|
|
5
|
-
```J
|
7
|
+
```HTML&JS
|
8
|
+
|
9
|
+
<!DOCTYPE html>
|
10
|
+
|
11
|
+
<meta charset="UTF-8">
|
12
|
+
|
13
|
+
<title>A23</title>
|
14
|
+
|
15
|
+
<style>
|
16
|
+
|
17
|
+
td, input[type="button"] {
|
18
|
+
|
19
|
+
font-size: xx-large;
|
20
|
+
|
21
|
+
border: 2px gray ridge;
|
22
|
+
|
23
|
+
border-radius: 40px;
|
24
|
+
|
25
|
+
padding: 1ex 1em;
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
</style>
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
<body>
|
34
|
+
|
35
|
+
<table id="A">
|
36
|
+
|
37
|
+
<tr><td><td><td>
|
38
|
+
|
39
|
+
<tr><td><td><td>
|
40
|
+
|
41
|
+
</table>
|
42
|
+
|
43
|
+
<p>
|
44
|
+
|
45
|
+
<input type="button" value="L">
|
46
|
+
|
47
|
+
<input type="button" value="Reset">
|
48
|
+
|
49
|
+
<input type="button" value="R"><br>
|
50
|
+
|
51
|
+
<input type="text" size="40" value="" id="S">
|
52
|
+
|
53
|
+
</p>
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
<script>
|
6
58
|
|
7
59
|
class A23 {
|
8
60
|
|
@@ -20,6 +72,8 @@
|
|
20
72
|
|
21
73
|
this.map = [a,e,b,d,f,c];
|
22
74
|
|
75
|
+
this.history += 'R';
|
76
|
+
|
23
77
|
return this;
|
24
78
|
|
25
79
|
}
|
@@ -32,6 +86,8 @@
|
|
32
86
|
|
33
87
|
this.map = [b,e,c,a,d,f];
|
34
88
|
|
89
|
+
this.history += 'L';
|
90
|
+
|
35
91
|
return this;
|
36
92
|
|
37
93
|
}
|
@@ -42,6 +98,8 @@
|
|
42
98
|
|
43
99
|
[...str].forEach (s=> this[s]());
|
44
100
|
|
101
|
+
this.history += str;
|
102
|
+
|
45
103
|
return this;
|
46
104
|
|
47
105
|
}
|
@@ -51,6 +109,8 @@
|
|
51
109
|
reset (LR = '', map = [0, 1, 2, 3, 4, 5]) {
|
52
110
|
|
53
111
|
this.map = map;
|
112
|
+
|
113
|
+
this.history = '';
|
54
114
|
|
55
115
|
return this.advance (LR);
|
56
116
|
|
@@ -68,10 +128,54 @@
|
|
68
128
|
|
69
129
|
|
70
130
|
|
71
|
-
|
131
|
+
//____________________________
|
72
|
-
|
73
|
-
console.log(a.map);
|
74
132
|
|
75
133
|
|
76
134
|
|
135
|
+
function disp () {
|
136
|
+
|
137
|
+
[...A.querySelectorAll ('td')]
|
138
|
+
|
139
|
+
.forEach ((e, i)=> e.textContent = a23.map[i]);
|
140
|
+
|
141
|
+
S.value = a23.history;
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
function handler ({target: e}) {
|
148
|
+
|
149
|
+
let { type, value } = e;
|
150
|
+
|
151
|
+
if ('button' === type)
|
152
|
+
|
153
|
+
switch (e.value) {
|
154
|
+
|
155
|
+
case 'L' : a23.L (); break;
|
156
|
+
|
157
|
+
case 'R' : a23.R (); break;
|
158
|
+
|
159
|
+
case 'Reset': a23.reset ();
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
disp ();
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
const a23 = new A23;
|
170
|
+
|
171
|
+
disp ();
|
172
|
+
|
173
|
+
document.addEventListener ('click', handler, false);
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
</script>
|
180
|
+
|
77
181
|
```
|