I have list of statuses where not started is the minimum , followed by submitted and last is complete.
So if we apply the logic on the data since there are 2 status on the current array of object below which are "Not Started" and "Submitted" so the function should return Not Started because not started is the min.
If there is only 1 item in an array then get the only status as a result.
How do we filter the array of objects and get the min based on the order in statuses array. Thanks for any idea.
#currentCode
getMin(id:number , key:string) {
let data = [
{
"id": 14,
"status": "Submitted",
},
{
"id": 15,
"status": "Not Started",
}
]
let min = Math.min(...data.map(item => item.status));
console.log('result' , min)
}
#order of statuses
statuses: any[] = [
{ viewValue: 'Not Started', value: 1 },
{ viewValue: 'Submitted', value: 2 },
{ viewValue: 'Complete', value: 3 },
]
#sample array of objects - result Not Started
data = [
{
"id": 14,
"status": "Submitted",
},
{
"id": 15,
"status": "Not Started",
}
]
#sample array of objects - result Submitted
data = [
{
"id": 14,
"status": "Submitted",
},
{
"id": 17,
"status": "Complete",
}
]
#sample array of objects - result Complete , since there is only 1 get the only status
data = [
{
"id": 17,
"status": "Complete",
}
]