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: 
Not the best solution perhaps, but this should help you in the right direction.
This sorts the array so that notes are in decending date order, with the pinned ones at the top.

Unlike other (better) answers, this has a O(2n) sorting complexity, so bear that in mind.

```js
const notes = [
  {
    text: "foo",
    modified: 1583337610387,
    pinned: false
  },
  {
    text: "bar",
    modified: 1583337610388,
    pinned: true
  },
  {
    text: "baz",
    modified: 1583337610389,
    pinned: false
  },
  {
    text: "qux",
    modified: 1583337610390,
    pinned: true
  }
];

const sortedNotes = [...notes];
sortedNotes.sort((a, b) => a.modified > b.modified ? -1 : 1);
sortedNotes.sort((a, b) => (a.pinned === b.pinned) ? 0 : a.pinned ? -1 : 1);
console.log(sortedNotes);
```
Shorter, you can try

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

```