I'm trying to sort an array of objects that has a nullable boolean value and a title. If an item in the list has been set as important the "ReadUnderstood" is either true or false, and if not, it's null. I want the list to be ordered alphabetically if "ReadUnderstood" is true or null, but if the value is false, I want it to the top of the list.
The closest to what I want I got with the code below. This returns the list in alphabetical order with the items where "ReadUnderstood" is false at the top of the list. But the items where "ReadUnderstood" is true ends up at the end of the list instead of in the alphabetiacal order. Any help would be greatly appreciated.
items = [
{Title: 'A', ReadUnderstood: null},
{Title: 'C', ReadUnderstood: false},
{Title: 'E', ReadUnderstood: null},
{Title: 'B', ReadUnderstood: true},
{Title: 'D', ReadUnderstood: true},
{Title: 'F', ReadUnderstood: null},
]
items.sort((a, b) => {
return (b.ReadUnderstood != null && b.ReadUnderstood == false) - (a.ReadUnderstood != null && a.ReadUnderstood == false) || a.Title - b.Title;
})
Desired result:
items = [
{Title: 'C', ReadUnderstood: false},
{Title: 'A', ReadUnderstood: null},
{Title: 'B', ReadUnderstood: true},
{Title: 'D', ReadUnderstood: true},
{Title: 'E', ReadUnderstood: null},
{Title: 'F', ReadUnderstood: null},
]
falsevalues. Do they need to be sorted alphabetically as well?