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

183
Vistas
How to check object value unchanged based on timestamp?

I have an object with Timeseries and a value for showing a chart. The value updates often. I want to display the number of hours the value is unchanged.

For example: consider the below object, the value remains the same for some hours. I want to show how many hours it is unchanged. If any new value is different then want to update the hours to Zero.

obj = [{
  "value": 48.52062,
  "timestamp": 1652848223325
},
{
  "value": 48.52062,
  "timestamp": 1652838323281
},
{
  "value": 48.52062,
  "timestamp": 1652833823275
},
{
  "value": 51.71021,
  "timestamp": 1652830223280
},
{
  "value": 48.52062,
  "timestamp": 1652829323276
}]

I am trying to filter the object using obj.filter(e => e.value === 48.52062) and check that filtered object timestamps and calculate the hours of first object and last object timestamp

But, the filtered object returns even the old data, in this case, the data value is changed in between which is not a flatline. I just want to check only until the value last changed.

I am not sure, if this is the right way to do it. Here is the code:

var obj = [{
  "value": 48.52062,
  "timestamp": 1652848223325
},
{
  "value": 48.52062,
  "timestamp": 1652838323281
},
{
  "value": 48.52062,
  "timestamp": 1652833823275
},
{
  "value": 51.71021,
  "timestamp": 1652830223280
},
{
  "value": 48.52062,
  "timestamp": 1652829323276
}];

const x = obj.filter(e => e.value === 48.52062)
const timeStart = x[0].timestamp;
const timeEnd = x[x.length - 1].timestamp;


console.log(getHourDiff(timeStart, timeEnd));

function getHourDiff(start, end) {
   return Math.floor((end - start) / 3600000)
}

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