如何在JavaScript中将一个数字拆分为最多100个的块
const chunkByArray = (count: number, num: number = 10000) => {
console.log(count, num)
let chunks = new Array(Math.floor(count / num)).fill(num)
let remainder = count % num
if (remainder > 0) {
chunks.push(remainder)
}
return chunks
}
获取当天凌晨00:00:00到当前时间的时分秒长度
const selectType = ref(2),
setInterDelay = {
3: {
time: 1000,
},
2: {
time: 60 * 1000,
},
1: {
time: 60 * 60 * 1000,
},
}
const getYCount = () => {
const { time } = setInterDelay[selectType.value]
let currentDay = date.value !== moment().format('YYYY-MM-DD'),
startDate = date.value + ' 00:00:00',
endDate = currentDay ? date.value + ' 23:59:59' : new Date(),
countTimeCha = new Date(startDate).getTime() - new Date(endDate).getTime(),
countDelay = Math.abs(countTimeCha / time).toFixed(),
count = currentDay ? Number(countDelay) : Number(countDelay) - 1
return count;
}
获取随机数
const getXTime = (idx: number) => {
let baseValue = Math.random() * 1000
let smallBaseValue = 0
function next(idx: number) {
smallBaseValue = idx % 30 === 0 ? Math.random() * 700 : smallBaseValue + Math.random() * 500 - 250
baseValue += Math.random() * 20 - 10
return Math.max(0, Math.round(baseValue + smallBaseValue) + 3000)
}
return next(idx).toFixed(2)
}
Math.random()
Math.random().toString().slice(2, 6)