js分钟根据时间间隔分割?
function minuteInterval(interval) { const minute = 60
return [15, 30, 45]
}
minuteInterval(15)
// 根据传入的间隔返回对应时间,如果传入5,则返回每隔5的集合[5, 10, 15, 20]
回答:
function minuteInterval(interval, max = 60, includeMax = false) { const result = [];
let n = 0;
max = includeMax ? max + interval : max;
while ((n + 1) * interval < max) {
result.push((n + 1) * interval);
n += 1;
}
return result;
}
回答:
我有个笨办法:
js">function minuteInterval(interval) { const minute = 60
var start = 0,res = [];
for(i=0;i<minute;i+=interval) {
start += interval
if(start < minute) {
res.push(start)
}
}
return res
}
minuteInterval(5)
回答:
这样?
function minuteInterval(interval) { return Array.from({length: Math.floor(60 / interval) - 1}, (v, i) => (i + 1) * interval);
}
回答:
npm install lodash
const minuteInterval = interval => _.range(interval, 60, interval)
以上是 js分钟根据时间间隔分割? 的全部内容, 来源链接: utcz.com/p/933034.html