One quick remark:
if (N === 0) return true;
can be replaced by
if (N <= 1) return true;
because in a non-empty array each element is a single "consecutive number." This saves the sorting of the array in the case \$ N = 1 \$.
Martin R
- 24.2k
- 2
- 38
- 96
default