Group an array of objects according to a common key