I am working on extracting the minimum and maximum values from a multidimensional JavaScript array based on two specific fields.
The data I receive is in timeseries format from an IoT device:
timestamp, device id, value1, value2, value3, etc.
To achieve this, I need to create a function that can determine the min/max values for each device based on a particular field.
Below is a sample of the array:
[
[
1577912341,
"ITEM1",
131.98840369
],
[
1577998742,
"ITEM2",
127.27418424
],
[
1578085141,
"ITEM2",
133.67909395
],
[
1578171541,
"ITEM1",
134.82513897
]
]
I am looking to find the min/max value for each unique item in field 1 using the value in field 3. For instance, I want to identify the max value of field 3 for (ITEM1), which in this case would be "134.82513897".
The min value of field 2 (ITEM1) is 131.98840369. The max value of field 2 (ITEM1) is 134.82513897.
The min value of field 2 (ITEM2) is 127.27418424. The max value of field 2 (ITEM2) is 133.67909395.