Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何每x数量检查一个数字_Javascript_Algorithm_Conditional Statements - Fatal编程技术网

Javascript 如何每x数量检查一个数字

Javascript 如何每x数量检查一个数字,javascript,algorithm,conditional-statements,Javascript,Algorithm,Conditional Statements,我需要为云函数编写一个条件语句,该函数运行创建的每个2016文档 所以我有一个变量,它在每次创建新文档时都会被迭代。在我看来,我想我可以用这一个变量来检查每一个x数量 当前创建的文档量只是一个随机数,而不是一个设定变量 const documentsCreated = 19239123; function checkDocuments(){ let x = (documentsCreated / 2016) % 2016; if(x === 2016){ retur

我需要为云函数编写一个条件语句,该函数运行创建的每个2016文档

所以我有一个变量,它在每次创建新文档时都会被迭代。在我看来,我想我可以用这一个变量来检查每一个x数量

当前创建的
文档量
只是一个随机数,而不是一个设定变量

const documentsCreated = 19239123;

function checkDocuments(){
    let x = (documentsCreated / 2016) % 2016;
    if(x === 2016){
      return true
    } else {
      return false
    }
}
此函数应返回
true
每次创建的
documents
都是2016的倍数


我很想只使用一个变量来实现这一点,但我想我可能必须保留第二个变量,每次它到达2016年时,我都会将其重置为0。

你应该检查mod在除法时是否等于0

 const documentsCreated = 19239123;

    function checkDocuments(){
        let x = documentsCreated % 2016;
        if(x === 0){
          return true
        } else {
          return false
        }
    }

在除法时,您应该检查mod是否等于0

 const documentsCreated = 19239123;

    function checkDocuments(){
        let x = documentsCreated % 2016;
        if(x === 0){
          return true
        } else {
          return false
        }
    }

documentsCreated%2016
对于2016的整数倍数将返回0。假设0应该返回false,那么
返回!(documentsCreated&&documentsCreated%2016)
documentsCreated%2016
将返回0表示2016的整数倍。假设0应该返回false,那么
返回!(documentsCreated&&documentsCreated%2016)
。非常感谢。这正是我想要的。不知道我是怎么想的,试着用模,谢谢。这正是我想要的。不知道我在想什么,试着用模。