Skip to main content
2 of 4
added 498 characters in body
Justin Mariner
  • 5k
  • 1
  • 13
  • 18

Japt, 11 bytes

ò¦ ®m<<Ãc x

Try it online!

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

Justin Mariner
  • 5k
  • 1
  • 13
  • 18