Arrays nodejs-值差大于2的独立数组
是否可以使用值差大于2的单独数组Arrays nodejs-值差大于2的独立数组,arrays,node.js,Arrays,Node.js,是否可以使用值差大于2的单独数组 [ '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '31', '32', '33', '34', '35', '36', '37', ] 我想这样分开 [ '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16'] [ '31', '32',
[
'6', '7', '8', '9', '10', '11', '12', '13', '14',
'15', '16', '31', '32', '33', '34', '35', '36', '37',
]
我想这样分开
[ '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16']
[ '31', '32', '33', '34', '35', '36', '37']
你可以试试这样的
“严格使用”;
常量数组=[1,2,3,4,5,7,8,10,11,12,13,14];
函数检测矩阵(数组){
常量结果=[];
让lastValue=null;
设currentSeries=[];
for(数组的常量currentValue){
if(lastValue==null){
lastValue=当前值;
}
如果(数学绝对值(currentValue-lastValue)>=2){
结果:推送(currentSeries);
currentSeries=[];
}
currentSeries.push(当前值);
lastValue=当前值;
}
结果:推送(currentSeries);
返回结果;
}
日志(detectAnomalies(数组));
到目前为止您尝试了什么?对于(让i=0;i