Forum Discussion
JohnBarulich1
7 years agoQrew Cadet
Thank you as usual, Dan!
[Event Time] is just a time of day. In the XML, since event_time is given to me as milliseconds, I converted these times to minutes and used Math.floor(time) since most were not whole numbers. Obviously not a very robust solution, do you have another idea?
Some context:
My overall goal is populate a field [Time Since Last Stop] for each record. Each [Event Time] represents when a vehicle has last stopped. So I wanted to iterate through each record and subtract
(most recent stop - second most recent stop = time since last stop)
I have created a 2D array to store pairs of [driver name, event time]. My goal is to iterate through this array, store the driver from the current index in a variable, compare it to subsequent indices of the array with a nested loop until we find the next index with the same driver, then perform basic calculation from those two event times.
My question is:
If I know the index of the array that I am performing the calculation on, how can I guarantee I reach the actual record given this index? What is another way (if you have an explanation or link) to iterate through each record WITHOUT a .each() call?
Also, if you have a more ideal solution off the top of your head, please don't hesitate to let me know. I am still learning!
[Event Time] is just a time of day. In the XML, since event_time is given to me as milliseconds, I converted these times to minutes and used Math.floor(time) since most were not whole numbers. Obviously not a very robust solution, do you have another idea?
Some context:
My overall goal is populate a field [Time Since Last Stop] for each record. Each [Event Time] represents when a vehicle has last stopped. So I wanted to iterate through each record and subtract
(most recent stop - second most recent stop = time since last stop)
I have created a 2D array to store pairs of [driver name, event time]. My goal is to iterate through this array, store the driver from the current index in a variable, compare it to subsequent indices of the array with a nested loop until we find the next index with the same driver, then perform basic calculation from those two event times.
My question is:
If I know the index of the array that I am performing the calculation on, how can I guarantee I reach the actual record given this index? What is another way (if you have an explanation or link) to iterate through each record WITHOUT a .each() call?
Also, if you have a more ideal solution off the top of your head, please don't hesitate to let me know. I am still learning!