Maintain the ordering of the original array, but group either negative or positive numbers into sub arrays
I think your code is great, but it is indeed way too verbose. It makes sense, but I got to admit, it took me some time. To me longer code isn't necessarily easier to understand. For instance your if/else really confused me at first.

Personally, I think you could have improved your code by making much shorter. Here's what I came up with :



function createSubArr(A) {
    let output = [];
    for(let i = 0; i &lt; A.length; i++) {
        let subArr = [A[i]];
        while(A[i] &gt; 0 === A[i + 1] &gt; 0) {
            subArr.push(A[i + 1]);
            i++;
        }
        output.push(subArr);
    }
    return output;
}

console.log(createSubArr([-1, -2, -3, 1, -1, -2, 2, 3, 4, -9, 5, 6, 7]))