When checking the value of statusC and adding a new value for statusP, the process is as follows: If all statusC values are ACCEPTED => statusP will be set to ACCEPTED. If all statusC values are REJECTED => statusP will be set to REJECTED. In the case where statusC has both ACCEPTED and REJECTED values => statusP will be set to COMPLETED.
- Create an Enum type to use throughout the code.
enum Status {
INPROGRESS = "INPROGRESS",
ACCEPTED = "ACCEPTED",
REJECTED= "REJECTED",
COMPLETED = "COMPLETED"
}
- Declare variable 'a':
let a= [
{
name:"test 1",
statusP : Status.INPROGRESS,
detail:[
{
nameC: "Test 2",
statusC: Status.REJECTED
},
{
nameC: "Test 3",
statusC: Status.ACCEPTED
}
]
}
];
- Check statusC values and update statusP accordingly*
const checkStatusC = a[0].detail.map(
(item)=>{
let b;
b = item.statusC;
if(b===Status.ACCEPTED){
a[0].statusP = Status.ACCEPTED
}else if (b === Status.REJECTED){
a[0].statusP = Status.REJECTED
} else if({?}){
a[0].statusP = Status.COMPLETED
}
}
)
Please provide a condition for {?}