I am sorting an array of object using the date values inside each object.
I now have an edge case, if thenoDate
property is set to true, that object shall be sorted after the object with the id 2.
An object looks something like this:
{
id: 1 // just simple ids 1...99
date: ...
noDate: true // true or false
}
Currently its sorted like this, but that does not provide the logic I need.
data.sort((a, b) => (!a.noDate - !b.noDate) || new Date(a.date) - new Date(b.date))
data.sort((a, b) => a.noDate ? -1 : new Date(a.date) - new Date(b.date) )