Alternative implementation using reduce and destructuring