猿问

如何补全一个时间数组万分感谢

如何将数组没五分钟补全如:将timeArray:['6:05','6:15','6:20','6:25','6:40','6:45','6:55','7:00','8:00','9:00'],补成timeArray:['6:05','6:10',6:15','6:20','6:25','6:30','6:35',6:40','6:45','6:50','6:55','7:00','7:05',········'8:00',········'9:00']
详细说一下我的问题:后台传过来三个数组timeArray:['6:05','6:15','6:20','6:25','6:40','6:45','6:55','7:00','8:00','9:00'],in:[10,20,50,60,40,70,50,80,20,10],out:[30,40,35,65,0,40,20,30,10,20],这时我要把时间这个数组补全成五点到二十四点,每五分钟的时间数组,而另外两个数组对没有这个时间间隔的数据进行补零['6:05','6:10',6:15','6:20','6:25','6:30','6:35',6:40','6:45','6:50','6:55','7:00','7:05',········'8:00',········'9:00']in:[0,········,10,0,20,50,60,0,0,40,70,50,80,········20,········10········],out:[········30,0,40,35,65,0,40,20,30,········,0,10,········,20,0,········],
慕斯709654
浏览 364回答 2
2回答

阿晨1998

设定一个开始时间和结束时间,然后开始到结束每次加5递增下去,注意时间的单位,每60分钟一小时,就是加到55后,小时加1,分钟从0又开始递增

皈依舞

从数组中获取时间的范围,然后自己按照规律把全部时间点生成出来。老实说补全是个很别扭的做法。以API设计的角度去看,要么所有值都由后台给出,要么后台只给出值的要求,前端自己生成合法的所有值。现在这种补全的做法把一个值的来源散布到前端和后端,出现问题很难查和很难维护的。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答