回答編集履歴

1

sample

2019/09/10 05:18

投稿

yambejp
yambejp

スコア116694

test CHANGED
@@ -13,3 +13,75 @@
13
13
  そのあたりの整理が必要です。(今のままだとソートや重複削除が必要)
14
14
 
15
15
  またできればフォーマットをあわせて"0509"みたいなデータにしたほうがやりやすいでしょう。
16
+
17
+
18
+
19
+ # sample
20
+
21
+ 配列が時間順に並んでいるなら次の電車はこんな感じです
22
+
23
+ ```javascript
24
+
25
+ var now = new Date();
26
+
27
+ var hour = (100+now.getHours()).toString().substr(-2);
28
+
29
+ var min = (100+now.getMinutes()).toString().substr(-2);
30
+
31
+ var hm=hour+min;
32
+
33
+ const times = [
34
+
35
+ "0509","0519","0529","0539","0549","0559",
36
+
37
+ "0609","0615","0621","0624","0628","0632","0636","0639","0642","0645","0649","0653","0656","0659",
38
+
39
+ "0701","0704","0707","0709","0711","0714","0717","0720","0723","0726","0728","0730","0733","0735","0737","0739","0742","0744","0746","0748","0751","0753","0755","0757",
40
+
41
+ "0800","0802","0804","0806","0809","0811","0813","0815","0818","0820","0822","0824","0827","0829","0831","0833","0836","0839","0841","0844","0844","0844","0847","0850","0853","0857",
42
+
43
+ "0900","0903","0906","0908","0912","0915","0918","0921","0925","0929","0932","0936","0940","0944","0948","0952","0956",
44
+
45
+ "1000","1004","1008","1012","1016","1020","1024","1028","1032","1036","1040","1044","1048","1052","1056",
46
+
47
+ "1100","1104","1108","1112","1116","1120","1124","1128","1132","1136","1140","1144","1148","1152","1156",
48
+
49
+ "1200","1204","1208","1212","1216","1220","1224","1228","1232","1236","1240","1244","1248","1252","1256",
50
+
51
+ "1300","1304","1308","1312","1216","1320","1324","1328","1332","1336","1340","1344",
52
+
53
+ //"1448","1352","1556",
54
+
55
+ "1400","1404","1408","1412","1416","1420","1424","1428","1432","1436","1440","1444","1448","1452","1456",
56
+
57
+ "1500","1504","1508","1512","1516","1520","1524","1528","1532","1536","1540","1544","1548","1552","1556",
58
+
59
+ "1600","1604","1608","1612","1616","1620","1624","1627","1630","1632","1635","1637","1640","1642","1645","1648","1650","1653","1656",
60
+
61
+ "1700","1703","1706","1708","1711","1714","1717","1719","1722","1724","1727","1729","1732","1734","1739","1742","1744","1747","1749","1752","1754","1757","1759",
62
+
63
+ "1802","1804","1807","1809","1812","1815","1818","1820","1823","1825","1828","1830","1833","1835","1838","1840","1843","1845","1848","1851","1854","1856","1858",
64
+
65
+ "1901","1904","1908","1911","1914","1918","1921","1924","1927","1931","1935","1939","1942","1945","1953","1956",
66
+
67
+ "2000","2004","2008","2011","2014","2018","2021","2024","2028","2031","2035","2040","2043","2047","2051","2054","2058",
68
+
69
+ "2101","2104","2104","2109","2114","2119","2124","2129","2134","2139","2144","2149","2154","2159",
70
+
71
+ "2204","2209","2214","2219","2224","2229","2234","2239","2244","2249","2254","2259",
72
+
73
+ "2304","2309","2313","2319","2324","2328","2332","2339","2345","2356",
74
+
75
+ ];
76
+
77
+
78
+
79
+ console.log(times.filter(x=>x>hm)[0]||null);
80
+
81
+ ```
82
+
83
+ ※上記たとえばhmが"2357"だったりしたらnullが返ります
84
+
85
+ もし24時以降の運行がある場合、現時刻が0時以降になると先頭がとられちゃうので
86
+
87
+ 工夫が必要になります