【发布时间】:2023-02-03 00:52:09
【问题描述】:
我想在下面对一个名为元数据的对象进行排序:
const metadata = {
glucose: {
name: 'Glucose',
units: 'mg/dL',
},
height: {
name: 'Height',
units: '"',
longUnit: 'Inches',
},
weight: {
name: 'Weight',
units: 'lbs',
longUnit: 'Pounds',
},
bmi: {
name: 'BMI',
},
pulse: {
name: 'Pulse',
},
temperature: {
name: 'Temperature',
units: 'F',
longUnit: 'Fahrenheit',
},
respiration_rate: {
name: 'Respiration Rate',
},
o2_saturation: {
name: 'O2 Saturation',
units: '%',
},
}
元数据需要根据 allVitals 的 taken_on 值中每个生命体征的名称进行排序。所以在这个例子中,根据 taken_on 时间,weight vital take_on 晚于 glucose taken_on。因此,在元数据排序中,重量将排在葡萄糖之前。 allVitals 数组可以有不止两个生命体征,它可以有所有类型的生命体征和其中的多个生命体征(即,多个脉搏生命体征,多个体重生命体征)
const allVitals =
[
{
"patient_id": 79,
"vital_type_id": 4,
"value": "171",
"taken_on": "2022-11-17T13:19:00.000-06:00",
"vital_type": {
"id": 4,
"name": "weight",
"units": "pounds",
"created_at": "2022-11-17T13:52:00.375-06:00",
"updated_at": "2022-11-17T13:52:00.375-06:00"
},
"notes": null,
"source": "patient_device",
"id": 1399,
"time_recorded": true,
"severity": null,
"formatted_severity": "-",
"vital_attributes": {},
"vital_status": "valid"
},
{
"patient_id": 79,
"vital_type_id": 6,
"value": "9.76",
"taken_on": "2022-11-17T11:07:00.000-06:00",
"vital_type": {
"id": 6,
"name": "glucose",
"units": "mg/dL",
"created_at": "2022-11-17T13:52:00.360-06:00",
"updated_at": "2022-11-17T13:52:00.360-06:00"
},
"notes": null,
"source": "patient_device",
"id": 1366,
"time_recorded": true,
"severity": "critical_low",
"formatted_severity": "Critical - Low",
"vital_attributes": {},
"vital_status": "valid"
}
]
【问题讨论】:
-
顺便说一句,您可以期望 allVitals 总是首先按最新的 vitals 排序
-
预期结果是什么?
标签: javascript arrays sorting object