I have the following code to go through an array of objects and find the object with a timestamp that is still smaller of a reference value but the biggest of those
for (const elem of objs) {
if (elem._time >= failureTime) {//we are one too far
break;
} else {
temp = elem; //this will end up as the last element with timestamp before event
}
}
This assumes that objs is ordered by timestamp, which I can't predict so I need to reorder it every time. I tried to create a .reduce function to solve that but horribly failed. Is there a way to do it?