Within my array of N objects, each object is structured with the following properties:
{
id: 'an id',
description: 'a description',
isUser: true/false
}
My goal is to sort this array based on two criteria:
Firstly, any object whose description contains 'dog', 'cat', or 'animal' should be placed higher in the order.
Secondly, if the value of isUser
is false
, it should also receive priority.
I've found that the standard sort
function is not effective for sorting by multiple attributes, so I am seeking guidance on the best approach to achieve this in Javascript (or using Lodash library which I currently utilize: https://lodash.com/)