I have an array of objects and one property is their statuses, I need to calculate the status following this: if all the statuses are failed return "failed", if all are canceled return "canceled", and so on, but if the array has one failed, or one canceled return "partially completed", I did, but I am looping a lot and I feel that exist a better and efficient way to do the same, this is my code:
function getComputedStatus(list) {
if (list.every(status => status.statusName == 'Failed'))
return 'Failed';
if (list.every(status => status.statusName == 'Canceled'))
return 'Canceled';
if (list.every(status => status.statusName == 'DidNotRun'))
return 'DidNotRun';
if (list.some(status => status.statusName == 'InProgress' ||
status.statusName == 'Pending'))
return 'InProgress';
if (list.some(status => status.statusName === 'Failed' ||
status.statusName === 'Canceled' ||
status.statusName === 'DidNotRun'))
return 'PartiallyCompleted';
return 'Completed';
}