I have the following array, and I want to sort it following these rules
- Primary true and shouldPrioritize true
- Primary true and shouldPrioritize false
- Primary false and shouldPrioritize true
- Primary false and shouldPrioritize false
const array = [{
primary: true
shouldPrioritize: false,
},
{
primary: true
shouldPrioritize: true,
}
{
primary: false
shouldPrioritize: true,
}
{
primary: false
shouldPrioritize: false,
}
]
What's the easiest way of using sort to match the rules? If we remove one of the items we should sort accordingly too.
question from:
https://stackoverflow.com/questions/65848756/javascript-how-to-sort-by-dynamic-property 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…