factor out Array#sum