How to sort an array by pattern in such way that elements non-existing in the pattern are not moved to the end of array but their order is preserved?

There is an example:

```
let input = ['Apple', 'Banana', 'Cherry', 'Grape', 'Mango', 'Orange', 'Peach']
let pattern = ['Orange', 'Peach', 'Banana', 'Grape']

// desired output
let output = ['Apple', 'Orange', 'Peach', 'Banana', 'Cherry', 'Grape', 'Mango']

```

Length of pattern may be equal, less or higher than input array's length.

Standard sorting:

```
input.sort( (a, b) => {
    let indexA = pattern.indexOf(a);
    let indexB = pattern.indexOf(b);
    return Math.sign(indexA - indexB);
});

// result:
// Apple,Cherry,Mango,Orange,Peach,Banana,Grape
// elements that are not present in pattern have been moved to the left

```

However, we want to preserve relative position of elements that are not present in pattern array. What is the most efficient way to achieve it?

Example of use: reordering table columns (some may be hidden but we remember their order).