Japt, 11 bytes
ò¦ ®m<<Ãc x
Explanation
Implicit input: [1, 1, 1, -1, -1, -1, -1, 1, 1]
ò¦
Partition input array (ò
) between different (¦
) elements:
[[1, 1, 1], [-1, -1, -1, -1], [1, 1]]
®m
Map each partition to itself (®
) with each element mapped to (m
)...
<<
The element, left-shifted over by the current index.
[[1, 2, 4], [-1, -2, -4, -8], [1, 2]]
Ãc x
End mapping (Ã
), flatten array (c
), and sum (x
).
[1, 2, 4, -1, -2, -4, -8, 1, 2]
=> -5