Javascript 如何使函数理解单个整数等于1

Javascript 如何使函数理解单个整数等于1,javascript,Javascript,我有一个函数,可以根据页面上的输入计算总帧数。我已经差不多完成了,但问题是如果我插入一个整数,比如7或83,那么我不知道如何让它计算,让它知道这是一个单帧。我想让它计算每次用户输入特定输入字段时的总帧数 下面是一个输入及其工作原理的示例 1-10 will render all frames from 1 to 10, and the total amount of frames is 10. 1-10,2 will render every second frame in the specif

我有一个函数,可以根据页面上的输入计算总帧数。我已经差不多完成了,但问题是如果我插入一个整数,比如
7
83
,那么我不知道如何让它计算,让它知道这是一个单帧。我想让它计算每次用户输入特定输入字段时的总帧数

下面是一个输入及其工作原理的示例

1-10 will render all frames from 1 to 10, and the total amount of frames is 10.
1-10,2 will render every second frame in the specified range of 1 to 10, and the total amount of frames is 5.
1-4;10-20,2 will render frames 1, 2, 3, 4, 10, 12, 14, 16, 18, 20, and the total amount of frames is 10.
1-4;10-20,2;83 will render frames 1, 2, 3, 4, 10, 12, 14, 16, 18, 20, 83, and the total amount of frames is 11.
7 will render frame number 7 and the total amount of frames will be 1.
83 will render frame number 83 and the total amount of frames will be 1. 

So `;` is like a separator
x - y is from frame x to frame y
x - y , z is every z frame between frame x and frame y
var-totFrames=0;
函数检查(){
var输入=document.getElementById(“id_desiredFrames”).value;
var chunk=input.split(“;”);
forEach(processChunk);
if(totFrames&&totFrames!==0){
document.getElementById(“TotalFrames”).value=totFrames;
总帧数=0;
}否则{
document.getElementById(“TotalFrames”).setAttribute(“type”,“hidden”);
}
}
函数processChunk(chunk){
var stepInfo=chunk.split(“,”);
var阶跃=1;
如果(stepInfo.length>1&&stepInfo[1]>1)step=stepInfo[1];
var range=stepInfo[0]。拆分(“-”);
变量帧=数学舍入((范围[1]-范围[0]+1)/步);
如果(帧和帧>0){
总帧数+=帧;
}否则{
总帧数=0;
}
}


<>代码>你没有考虑你能提供一个像这个例子的例子:<强> 1-4;10-20,2;8383没有对。此外,当frame为1时,您正在将totFrame重置为0&&stepInfo[1]>1)step=stepInfo[1]; var range=stepInfo[0]。拆分(“-”); var帧=0; //看看你得到了什么 如果(range.length==1){ //这里只有一帧 帧=1; }否则{ //可能需要检查范围[1]是否大于范围[0] //使用parseInt将值转换为整数 frame=parseInt(范围[1])-parseInt(范围[0]); } 如果(帧>0){ 总帧数+=帧; //否则会重置计数器,您不需要它 //}其他{ //总帧数=0; } }