I'm trying to slice an array at i + 1 from the last null value.
The array is sorted to have null values first.
This is how it should behave:
[null, null, a, b, c] => [null, null, a, b]
[null, a, b, c] => [null, a, b]
[null, null] => [null, null]
I'm doing something like this but I'm not sure how to handle the null only arrays.
let newArray: = [];
for (let i = 0; i < array.length; i++) {
if (array[i] !== null) {
newArray = array.slice(0, i + 1);
i++;
}
}
nullvalues later in the array?