So I have a an array ob objects (recentHistory) and each stores a value - an exchange rate for a particular date.
Now I'm writing a getter that should be able to calculate the difference between the rates of day1 and day2, day2 and day3, day3 and day4 etc.
public get change(): number {
//return this.store.recentHistory[0].rate - this.store.recentHistory[1].rate;
this.store.recentHistory.reduce((prev, item, index) => {
return prev.rate - item.rate /????
})
The commented line was my first idea but apparently it won't work as I need because it would return only the difference between today's rates and yesterdays. And I need the getter to output one value - the difference between the days rates, kinda: this.store.recentHistory[index].rate - this.store.recentHistory[index + 1].rate
I don't quite understand how to code this, so I appreciate any advice
I'm not sure my attempt is correct, because I see the error (below)
this.store.recentHistory.reduce((prev, item, index) => {
return prev.rate - item.rate
Argument of type '(prev: HistoryCard, item: HistoryCard, index: number) => number' is not assignable to parameter of type '(previousValue: HistoryCard, currentValue: HistoryCard, currentIndex: number, array: HistoryCard[]) => HistoryCard'. Type 'number' is not assignable to type 'HistoryCard'.