Question: I have an array with classes (the class is called `Note`), and in those classes are basic values. Two important values are the `Note.Pinned` (boolean whether it's pinned or not) and `Note.Modified` (a timestamp when it was last edited).

I would like to sort this array of classes by the `Modified` timestamp, then reorder it that the `Pinned` notes are on top of this list.

I already tried sorting the notes.

```js
const SortedNotes = Notes.sort((a, b) => a.Modified > b.Modified);

```

`Notes` being the array with classes.

But, then, is there a better way to rearrange this array? Or is this the only method I can use?

```js
SortedNotes.filter(n => n.Pinned).concat(SortedNotes.filter(n => !n.Pinned));

```

The above would work, and I know I can use `Array.prototype.partition`, so is there any other way of doing this?

Thanks

Answer: 
You can sort by multiple conditions:

```js
const SortedNotes = Notes.sort((a, b) => {
  if (a.Pinned == b.Pinned) {
    if (a.Modified > b.Modified) return -1;
    if (a.Modified < b.Modified) return 1;
  } else {
    return a.Pinned ? -1 : 1;
  }
});

```

The missing branch of `a.Pinned == b.Pinned && a.Modified == b.Modified` would return `undefined`, which in turn would be interpreted as equal.

Btw, the array `Notes` itself would've been modified in place, so both `SortedNotes` and `Notes` would exhibit the same ordering; of course, assigning to a `const` variable can't hurt.
I edited @Ja͢ck's answer to be a little more compact.

```js
const SortedNotes = Notes.sort((a, b) => {
    if (a.Pinned == b.Pinned) return a.Modified > b.Modified ? -1 : 1;
    else return a.Pinned ? -1 : 1;
});

```