%dw 2.0
output application/dw

var customShippings =
    in0."batch-order".shipping
        map ((shipping, i) ->
            shipping ++
                {
                    continue: in0."batch-order".shipping filter ((secondShipping, index) ->
                        secondShipping.origin == shipping.destination
                    )
                }
        )


var customShippings2 = customShippings reduce ((ship1, acc1 = {} ) ->
   acc1 ++ {orig: ship1.origin , cont: ship1.continue map ((item, index) -> ship1.origin)}
)
---
 {
    reduce: customShippings2,
    map: [{a:1, b:[1]},{a:2, b:[1,2]},{a:3, b:[1,2,3]},{a:4, b:[1,2,3,4]}]
            map
            ((item, index) -> {a: item.a,b: item.b map ((z, index) -> item.a)})
 }