Ale*_*omb 1 javascript algorithm conditional-statements
我需要为每个 2016 年创建的文档运行的云函数编写一个条件语句。
所以我有一个变量,每次创建新文档时都会对其进行迭代。在我看来,我认为我可以使用这个变量来检查每个 x 数量。
当前的数量documentsCreated只是一个随机数,而不是一个集合变量。
const documentsCreated = 19239123;
function checkDocuments(){
let x = (documentsCreated / 2016) % 2016;
if(x === 2016){
return true
} else {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
true每次documentsCreated是 2016 的倍数时,此函数都应返回。
我很想只用一个变量来做到这一点,但我想我可能必须保留第二个变量,每次到 2016 年时我都会将其重置为 0。
您应该检查除法时 mod 是否等于 0。
const documentsCreated = 19239123;
function checkDocuments(){
let x = documentsCreated % 2016;
if(x === 0){
return true
} else {
return false
}
}
Run Code Online (Sandbox Code Playgroud)