I'm learning ES6:
function* consec(array) {
let arr = array.splice(0);
while (arr.length > 0) {
let nextSeqIndex = arr.findIndex((v, i, a) => v != a\[0\] + i);
if (nextSeqIndex === -1) return yield arr;
yield arr.splice(0, nextSeqIndex);
}
}
let array = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 22];
for (let sub of consec(array)) {
console.log(sub);
}