How does push!() work within accumulate()?

push! mutates a vector, while concatenation with [s; c] creates a completely new vector. In the first case, you’re mutating that same initial vector [] over and over, so each element in the result is the same vector and has the same value. In the second case, you’re creating a brand new vector with [s; c] at each iteration, so the accumulated results aren’t all identical.

1 Like