>>106309319
I'm (
>>106309125) getting 5, but I barely know what I'm doing. Here's the code:
let lst = [1, 3, 0, 0, 2, 0, 0, 4];
function separateByDelimiter(arr, delimiter) {
return arr.reduce((result, num) => {
if (num === delimiter) {
result.push([]);
} else {
result[result.length - 1].push(num);
}
return result;
}, [[]]).filter(subArr => subArr.length > 0);
}
let separatedlst = separateByDelimiter(lst, 0);
let totalSubarrays = separatedlst.reduce((acc, curr) => {
const n = curr.length;
const numSubarrays = (n * (n + 1)) / 2;
return acc + numSubarrays;
}, 0);
I think is pretty self-explanatory, separateByDelimiter gives the subarrays, then I use the formula ((n(n+1))/2) to get me all the possible combinations after checking for each subarray length. Got the formula from ChatGPT, dunno if that shit is hallucinated.