我需要为每创建一个 2016 文档就运行的云函数编写一个条件语句。
所以我有一个变量,每次创建新文档时都会对其进行迭代。在我看来,我认为我可以使用这个变量来检查每个 x 数量。
当前 documentsCreated
的数量只是一个随机数,不是一个设置变量。
const documentsCreated = 19239123;
function checkDocuments(){
let x = (documentsCreated / 2016) % 2016;
if(x === 2016){
return true
} else {
return false
}
}
每当 documentsCreated
是 2016 年的倍数时,此函数应返回 true
。
我很想只用一个变量来做到这一点,但我想我可能必须保留第二个变量,每次到 2016 年我都会将其重置为 0。
最佳答案
除法时,你应该检查 mod 是否等于 0。
const documentsCreated = 19239123;
function checkDocuments(){
let x = documentsCreated % 2016;
if(x === 0){
return true
} else {
return false
}
}
关于javascript - 如何每 x 金额检查一个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54282820/