回答編集履歴
2
chousei
test
CHANGED
@@ -226,7 +226,11 @@
|
|
226
226
|
|
227
227
|
r.push([time,name]);
|
228
228
|
|
229
|
+
//r=await r.sort((x,y)=>x[0]>y[0]).splice(0,5);
|
230
|
+
|
231
|
+
//以下修正版
|
232
|
+
|
229
|
-
r=await r.sort((x,y)=>x[0]>y[0]).splice(0,5);
|
233
|
+
r=await r.sort((x,y)=>x[0]>y[0]?1:-1).splice(0,5);
|
230
234
|
|
231
235
|
viewRank();
|
232
236
|
|
1
kairyou
test
CHANGED
@@ -117,3 +117,141 @@
|
|
117
117
|
|
118
118
|
|
119
119
|
```
|
120
|
+
|
121
|
+
# 改良版
|
122
|
+
|
123
|
+
- 問題をシャッフルして順番に表示
|
124
|
+
|
125
|
+
- ランキングをいつも表示
|
126
|
+
|
127
|
+
```javascript
|
128
|
+
|
129
|
+
<script>
|
130
|
+
|
131
|
+
var r=[
|
132
|
+
|
133
|
+
['00:30.00','abc'],
|
134
|
+
|
135
|
+
['01:00.00','xyz'],
|
136
|
+
|
137
|
+
['01:30.00','ijk'],
|
138
|
+
|
139
|
+
['02:30.00','aaa'],
|
140
|
+
|
141
|
+
['03:00.00','zzz'],
|
142
|
+
|
143
|
+
];
|
144
|
+
|
145
|
+
var qs=[
|
146
|
+
|
147
|
+
'Hello World',
|
148
|
+
|
149
|
+
'Good',
|
150
|
+
|
151
|
+
'I love JavaScript',
|
152
|
+
|
153
|
+
'This is MyApp',
|
154
|
+
|
155
|
+
'Welcome'
|
156
|
+
|
157
|
+
];
|
158
|
+
|
159
|
+
const viewRank=()=>{
|
160
|
+
|
161
|
+
document.querySelector('#rank span').innerHTML=r.map(x=>x.join(" ")).join("<br>");
|
162
|
+
|
163
|
+
};
|
164
|
+
|
165
|
+
window.addEventListener('DOMContentLoaded',()=>{
|
166
|
+
|
167
|
+
viewRank();
|
168
|
+
|
169
|
+
document.querySelector('#start').addEventListener('click',e=>{
|
170
|
+
|
171
|
+
const t1=e.target;
|
172
|
+
|
173
|
+
const t2=document.querySelector('#a');
|
174
|
+
|
175
|
+
t1.disabled=true;
|
176
|
+
|
177
|
+
t2.disabled=false;
|
178
|
+
|
179
|
+
const name=prompt("your name?");
|
180
|
+
|
181
|
+
if(name=="") name="noname";
|
182
|
+
|
183
|
+
(async()=>{
|
184
|
+
|
185
|
+
qs=qs.map(x=>[x,Math.random()]).sort((x,y)=>x[1]-y[1]).map(x=>x[0]);
|
186
|
+
|
187
|
+
const s=new Date().getTime();
|
188
|
+
|
189
|
+
for(var i=0;i<qs.length;i++){
|
190
|
+
|
191
|
+
const qStr=qs[i];
|
192
|
+
|
193
|
+
document.querySelector('#q span').textContent=qStr;
|
194
|
+
|
195
|
+
t2.value="";
|
196
|
+
|
197
|
+
t2.focus();
|
198
|
+
|
199
|
+
await new Promise(resolve=>{
|
200
|
+
|
201
|
+
const timerId=setInterval(()=>{
|
202
|
+
|
203
|
+
if(t2.value==qStr){
|
204
|
+
|
205
|
+
clearInterval(timerId);
|
206
|
+
|
207
|
+
resolve();
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
},10);
|
212
|
+
|
213
|
+
});
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
const e=new Date().getTime();
|
218
|
+
|
219
|
+
const diff=e-s;
|
220
|
+
|
221
|
+
const str=(10000+diff/1000).toString();
|
222
|
+
|
223
|
+
const time=str.substr(1,2)+":"+
|
224
|
+
|
225
|
+
str.substr(3,5);
|
226
|
+
|
227
|
+
r.push([time,name]);
|
228
|
+
|
229
|
+
r=await r.sort((x,y)=>x[0]>y[0]).splice(0,5);
|
230
|
+
|
231
|
+
viewRank();
|
232
|
+
|
233
|
+
t1.disabled=false;
|
234
|
+
|
235
|
+
t2.disabled=true;
|
236
|
+
|
237
|
+
})();
|
238
|
+
|
239
|
+
});
|
240
|
+
|
241
|
+
});
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
</script>
|
246
|
+
|
247
|
+
<input type="button" value="start" id="start">
|
248
|
+
|
249
|
+
<div id="q">Q:<span></span></div>
|
250
|
+
|
251
|
+
<div>A:<input type="text" id="a"></div>
|
252
|
+
|
253
|
+
<div id="rank">rank:<br>
|
254
|
+
|
255
|
+
<span></span></div>
|
256
|
+
|
257
|
+
```
|