Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
how to calculate the difference between current and previous values? should I use reduce?

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'.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda