如果数组在 javaScript 中是连续的,则将其拆分为数组块

Split array into chunks of array if it is sequential in javaScript

我想在数组块中溢出数组 输入= [36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,57,58 ,59,60,61,62] 输出= {[36,37,38,39],[40,41,42,43],[44,45,46,47],[48,49,50, 51],[57,58,59,60]}

If there are no sequential numbers from 52 so it should not take that.
Can anyone help me out?
Thanks in advance.

I am currently using this code but in output it is not checking the sequence

    ```Array.prototype.chunk = function(n) {
      if (!this.length) {
        return [];
      }
      return [this.slice(0, n)].concat(this.slice(n).chunk(n));
    };
    console.log([36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72].chunk(4));    ```
This output is what i am currently getting but i want output as i mentioned above.
Output:

[
  [ 36, 37, 38, 39 ],
  [ 40, 41, 42, 43 ],
  [ 44, 45, 46, 47 ],
  [ 48, 49, 50, 51 ],
  [ 52, 57, 58, 59 ],
  [ 60, 61, 62, 63 ],
  [ 64, 65, 66, 67 ],
  [ 68, 69, 70, 71 ],
  [ 72 ]
]
      

不确定这是否符合您的预期,但您将以这种方式获得预期的输出

console.log(chunk([36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72], 4));

function checkSequence(arr) {
  for (let i = 1; i < arr.length; i++) {
    if (arr[i] - arr[i - 1] > 1) {
      return false;
    }
  }
  return true;
}
function chunk(arr, n) {
  let i = 0;
  var arr1 = [];
  while (i < arr.length) {
    const res = arr.slice(i, i + n);
    if (checkSequence(res) && res.length === 4) {
      arr1.push(res);
      i = i + n;
    } else {
      i = i + 1;
    }
  }
  return arr1;
}