|
本帖最后由 wjz 于 2017-6-1 09:49 编辑
数组里面有7个整数,如果其中有5个是连续的数字,就提取出来。写了下面代码,不太对,求助大家帮忙分析下。
import console
tab={4;6;7;8;9;10;12}
comProc = function(b) {
return owner > b ;
}
table.sort(tab,comProc)
j=0
for(ii=1;#tab-1;1){
if(tab[ii]-tab[ii+1]=1){
j++
}
}
if(tonumber(j)>=4 and tab[3]-tab[4]=1 and tab[4]-tab[5]=1 ){
sindex=3;eindex=7
if(tab[1]-tab[2]=1 and tab[2]-tab[3]=1 and tab[3]-tab[4]=1 ){
sindex=1;eindex=5
}
}
tab_slice=table.slice(tab,sindex,eindex)
console.log(table.tostring(tab_slice))
//tab={4;5;7;8;9;10;12} 遇到这种不符合要求的不要提出 |
|