reduce once instead of thrice
This commit is contained in:
parent
d28cc9b3f7
commit
f64fbfb71d
@ -34,14 +34,18 @@ const blockGasPricesObservable = new Observable<GasPrices>((observer) => {
|
||||
const averageGasPricesObservable = blockGasPricesObservable.pipe(
|
||||
scan((acc, curr) => [...acc.slice(-19), curr], [] as GasPrices[]),
|
||||
map((blocks) => {
|
||||
const fastSum = blocks.reduce((sum, block) => sum + block.fast, 0);
|
||||
const averageSum = blocks.reduce((sum, block) => sum + block.average, 0);
|
||||
const slowSum = blocks.reduce((sum, block) => sum + block.slow, 0);
|
||||
const { fast, average, slow } = blocks
|
||||
.reduce((sum, block) =>
|
||||
({
|
||||
fast: sum.fast + block.fast,
|
||||
average: sum.average + block.average,
|
||||
slow: sum.slow + block.slow
|
||||
}), { fast: 0, average: 0, slow: 0 } as GasPrices);
|
||||
return {
|
||||
fast: Math.round(fastSum / blocks.length),
|
||||
average: Math.round(averageSum / blocks.length),
|
||||
slow: Math.round(slowSum / blocks.length),
|
||||
};
|
||||
fast: Math.round(fast / blocks.length),
|
||||
average: Math.round(average / blocks.length),
|
||||
slow: Math.round(slow / blocks.length),
|
||||
} as GasPrices;
|
||||
})
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user