You can simplify this even further:

`var items = ( changedItems && state ) ? changedItems : cartItems;`

And then you only need one `for` loop section below.