sort objects by another array JS
const machines = [
{ id: 1, client: 'Machine A', state: 'Ready' },
{ id: 2, client: 'Machine B', state: 'Stopped' },
{ id: 3, client: 'Machine C', state: 'Active' },
{ id: 4, client: 'Machine D', state: 'Stopped' },
{ id: 5, client: 'Machine E', state: 'Active' },
{ id: 6, client: 'Machine F', state: 'Stopped' }
]
const sortedBy = {
'Active' : 0,
'Ready' : 1,
'Stopped' : 2,
}
const result = machines.sort(
(a, b) => sortedBy[a.state] - sortedBy[b.state]
)