Let's say I have this array of observables:
animals$ = from([
{ animal: 'rat', color: 'grey', speed: 2 },
{ animal: 'rat', color: 'black', speed: 3 },
{ animal: 'dog', color: 'grey', speed: 2 },
{ animal: 'dog', color: 'black', speed: 1 },
{ animal: 'cat', color: 'grey', speed: 5 },
{ animal: 'cat', color: 'black', speed: 1 },
]);
I want to get an observable array of the following format, where the results have been grouped by animal type, sorted alphabetically by animal, and the color values are transformed to keys for speed values:
[
{ animal: 'cat', grey: 5, black: 1 },
{ animal: 'dog', grey: 2, black: 1 },
{ animal: 'rat', grey: 1, black: 3 },
]
Is it possible by using groupBy? Most examples I have found so far are quite different, where in the results are in an array rather than combined to make key/value pairs.