js如何判断一组数字是否连续,得到一个临时数组[[3,4],[13,14,15],[17],[20],[22]];
var arrange = function(arr){
var result = [],
temp = [];
arr.sort(function(source, dest){
return source - dest;
}).concat(Infinity).reduce(function(source, dest){
temp.push(source);
if(dest-source>1){
result.push(temp);
temp = [];
}
return dest;
});
return result;
};
var arr=[3, 4, 13 ,14, 15, 17, 20, 22];
console.log(arrange(arr));