function fn(arr){
var result = [],
i = 0;
result[i] = [arr[0]];
arr.reduce(function(prev, cur){
cur-prev === 1 ? result[i].push(cur) : result[++i] = [cur];
return cur;
});
return result;
}
function fn(arr){
var result = [],
i = 0;
result[i] = [arr[0]];
arr.reduce(function(prev, cur){
cur-prev === 1 ? result[i].push(cur) : result[++i] = [cur];
return cur;
});
return result;
}
本文标题:获取一个数组中的连续数字
本文链接:https://www.haomeiwen.com/subject/pnkhmftx.html
网友评论