how to create an array of times with half hour intervals instead of declare in variable

余生颓废 提交于 2019-12-02 05:37:39

I don't think you can reduce it. This may not help, but here is JS version :

var foo = [];
for (var i = 0; i <= 48; i++) {
   var n = i%2==0 ? i/2+'.00' : (i+1)/2-1+'.30';
    if(n<10) //zero-left padding
   n = '0'+n;
   foo.push(n);
}
console.log(foo);

Below code works for me I have tried using https://stackoverflow.com/a/8043061/9516784

    var hrs = [];
    for (var i = 0; i <= 48; i++) {
      var n = i%2==0 ? i/2+'.00' : (i+1)/2-1+'.30';
      if(n<10) {
        n = '0'+n;
      }   
      hrs.push(n);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!